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 after the application boots. Layer values win over defaults.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$path | string | Absolute path to the config file |
$key | string | Config key to merge into (e.g. 'orders') |
Example:
$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 | After app()->booted() |
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
);
}
public function boot(): void
{
$this->loadMigrationsFrom(__DIR__ . '/../../database/migrations');
$this->loadSeeders([BillingSeeder::class], priority: -10); // billing data seeded first
$this->overrideConfigFrom(__DIR__ . '/../../config/billing.php', 'billing');
$this->loadRoutesFrom(__DIR__ . '/../../routes/api.php');
}
}