diff --git a/app/Helpers/helpers.php b/app/Helpers/helpers.php index c98a0ce..31b4d78 100644 --- a/app/Helpers/helpers.php +++ b/app/Helpers/helpers.php @@ -49,6 +49,10 @@ function modules_path(string $path = ''): string */ function modules(bool $withDisabled = false): Collection { + if (temp_cache()->has('modules')) { + return temp_cache('modules'); + } + /** @var array */ $modulesDir = File::directories(modules_path()); $modules = collect(); @@ -74,5 +78,19 @@ function modules(bool $withDisabled = false): Collection } } + temp_cache()->put('modules', $modules); + return $modules; } + +/** + * Temprory cache for single request + */ +function temp_cache(string $key = ''): mixed +{ + $tempCache = cache()->driver('array'); + + return ($key !== '') + ? $tempCache->get($key) + : cache()->driver('array'); +} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 1392870..0fe693a 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -31,6 +31,11 @@ class AppServiceProvider extends ServiceProvider */ public function registerModules(): void { - modules(); + $migrationDirectories = []; + modules()->each(function ($module) use (&$migrationDirectories) { + is_dir($module['path'].'/Database/Migrations') ? array_push($migrationDirectories, $module['path'].'/Database/Migrations') : ''; // @phpstan-ignore-line + }); + + $this->loadMigrationsFrom($migrationDirectories); } }