LayerServiceProvider
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:
| Parameter | Type | Description |
|---|---|---|
$seeders | array<class-string> | Array of seeder class names |
$priority | int | Execution 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.
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:
| Parameter | Type | Description |
|---|---|---|
$path | string | Absolute path to the config file |
$key | string | Config key to merge into (e.g. 'orders') |
Example:
public function register(): void
{
$this->overrideConfigFrom(
__DIR__ . '/../../config/orders.php',
'orders'
);
}
Comparison with mergeConfigFrom():
| Method | Priority | When it runs |
|---|---|---|
mergeConfigFrom() | Existing config wins | During register() |
overrideConfigFrom() | Layer config wins | During 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:
| Parameter | Type | Default | Description |
|---|---|---|---|
$web | array|string|null | null | Path(s) to web route files — loaded inside the web middleware group |
$api | array|string|null | null | Path(s) to api route files — loaded inside the api middleware group and prefixed with apiPrefix |
$commands | ?string | null | Path to console route file — required when running in console |
$channels | ?string | null | Path to broadcast channels file — required on every request |
$health | ?string | null | Health-check URI — registers GET {health} returning {"status":"ok"} |
$apiPrefix | string | '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
<?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',
);
}
}