54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\Event;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class AppServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
Model::shouldBeStrict(! app()->isProduction());
|
|
|
|
Event::listen(
|
|
events: ['eloquent.created: *', 'eloquent.updated: *', 'eloquent.deleted: *'],
|
|
listener: fn (string $eventName, array $data) => storeResourceEvent($eventName, $data, request())
|
|
);
|
|
|
|
$this->loadMigrationsFrom($this->findModuleMigrations());
|
|
}
|
|
|
|
/**
|
|
* Find Module migrations
|
|
*
|
|
* @return array<int, string>
|
|
*/
|
|
public function findModuleMigrations(): array
|
|
{
|
|
/** @var array<int, string> */
|
|
$modulesDir = scandir(modules_path());
|
|
|
|
$migrationDirectories = [];
|
|
foreach ($modulesDir as $module) {
|
|
if (is_dir(modules_path($module.'/Database/Migrations'))) {
|
|
$migrationDirectories[] = modules_path($module.'/Database/Migrations');
|
|
}
|
|
}
|
|
|
|
return $migrationDirectories;
|
|
}
|
|
}
|