API Reference

LayerServiceProvider

Abstract base class for all layer service providers.

Xefi\LaravelOSDD\LayerServiceProvider is an abstract class that extends Laravel's Illuminate\Support\ServiceProvider. Every layer's service provider should extend this class.

Namespace

use Xefi\LaravelOSDD\LayerServiceProvider;

Methods

loadSeeders(array $seeders, int $priority = 0): void

Pushes one or more seeder class-strings into the global SeederRegistry singleton. Seeders registered here are discovered and run by php artisan osdd:seed. The optional $priority parameter controls execution order — lower numbers run first; default is 0.

Parameters:

ParameterTypeDescription
$seedersarray<class-string>Array of seeder class names
$priorityintExecution priority (optional, default 0). Lower numbers run first.

Example:

// Default priority
$this->loadSeeders([
    OrdersSeeder::class,
    OrderStatusSeeder::class,
]);

// Run before other seeders (foundational data)
$this->loadSeeders([RolesSeeder::class], priority: -10);

overrideConfigFrom(string $path, string $key): void

Loads the PHP config file at $path and deep-merges it over the already-loaded config key $key. Layer values win over defaults. The merge runs synchronously inside the calling provider's lifecycle (no app()->booted() deferral) and is skipped entirely when config:cache has produced a cached config.

Call from register(), not boot(). Other packages may read their config during their own boot() (e.g. Horizon reads horizon.path/horizon.middleware while registering its routes) — the override must be in place by then.

Parameters:

ParameterTypeDescription
$pathstringAbsolute path to the config file
$keystringConfig key to merge into (e.g. 'orders')

Example:

public function register(): void
{
    $this->overrideConfigFrom(
        __DIR__ . '/../../config/orders.php',
        'orders'
    );
}

Comparison with mergeConfigFrom():

MethodPriorityWhen it runs
mergeConfigFrom()Existing config winsDuring register()
overrideConfigFrom()Layer config winsDuring register() (skipped if config is cached)

withRouting(web:, api:, commands:, channels:, health:, apiPrefix:): void

Mounts a layer's route files using Laravel's standard conventions. Mirrors Application::configure()->withRouting(...) at the layer level.

Parameters:

ParameterTypeDefaultDescription
$webarray|string|nullnullPath(s) to web route files — loaded inside the web middleware group
$apiarray|string|nullnullPath(s) to api route files — loaded inside the api middleware group and prefixed with apiPrefix
$commands?stringnullPath to console route file — required when running in console
$channels?stringnullPath to broadcast channels file — required on every request
$health?stringnullHealth-check URI — registers GET {health} returning {"status":"ok"}
$apiPrefixstring'api'Prefix applied to the api routes

The entire call is a no-op when Application::routesAreCached() returns true. Missing files are skipped silently — only existing files are loaded — so the generated withRouting(...) call is safe even if a layer hasn't scaffolded any route files yet.

Example:

public function boot(): void
{
    $this->withRouting(
        web:      __DIR__ . '/../../routes/web.php',
        api:      __DIR__ . '/../../routes/api.php',
        commands: __DIR__ . '/../../routes/console.php',
        channels: __DIR__ . '/../../routes/channels.php',
        health:   '/up',
    );
}

For anything beyond these conventions (custom prefixes, domains, named groups), drop down to the Route facade in boot() directly.


Inherited: loadMigrationsFrom(string $path): void

Inherited from Laravel's base ServiceProvider. Registers the given directory so php artisan migrate includes the layer's migrations.

$this->loadMigrationsFrom(__DIR__ . '/../../database/migrations');

Complete Example

src/Providers/BillingServiceProvider.php
<?php

namespace Functional\Billing\Providers;

use Xefi\LaravelOSDD\LayerServiceProvider;
use Functional\Billing\Database\Seeders\BillingSeeder;
use Functional\Billing\Contracts\NotifierInterface;
use Functional\Billing\Notifiers\MailInvoiceNotifier;

class BillingServiceProvider extends LayerServiceProvider
{
    public function register(): void
    {
        $this->app->bind(
            NotifierInterface::class,
            MailInvoiceNotifier::class
        );

        $this->overrideConfigFrom(__DIR__ . '/../../config/billing.php', 'billing');
    }

    public function boot(): void
    {
        $this->loadMigrationsFrom(__DIR__ . '/../../database/migrations');
        $this->loadSeeders([BillingSeeder::class], priority: -10); // billing data seeded first

        $this->withRouting(
            web:      __DIR__ . '/../../routes/web.php',
            api:      __DIR__ . '/../../routes/api.php',
            commands: __DIR__ . '/../../routes/console.php',
            channels: __DIR__ . '/../../routes/channels.php',
        );
    }
}