2026-01-26 10:37:47 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
|
|
|
|
|
|
class ModuleServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Register services.
|
|
|
|
|
*/
|
|
|
|
|
public function register(): void
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Bootstrap services.
|
|
|
|
|
*/
|
|
|
|
|
public function boot(): void
|
|
|
|
|
{
|
|
|
|
|
$modulesPath = app_path('Modules');
|
|
|
|
|
|
|
|
|
|
if (File::exists($modulesPath)) {
|
|
|
|
|
$modules = File::directories($modulesPath);
|
|
|
|
|
|
|
|
|
|
foreach ($modules as $module) {
|
|
|
|
|
// $moduleName = basename($module);
|
2026-01-26 14:59:24 +08:00
|
|
|
// Load Routes
|
2026-01-26 10:37:47 +08:00
|
|
|
$routesPath = $module . '/Routes/web.php';
|
|
|
|
|
if (File::exists($routesPath)) {
|
|
|
|
|
Route::middleware('web')
|
|
|
|
|
->group($routesPath);
|
|
|
|
|
}
|
2026-01-26 14:59:24 +08:00
|
|
|
|
|
|
|
|
// Load Service Provider
|
|
|
|
|
$moduleName = basename($module);
|
|
|
|
|
$providerClass = "App\\Modules\\{$moduleName}\\{$moduleName}ServiceProvider";
|
|
|
|
|
|
|
|
|
|
if (class_exists($providerClass)) {
|
|
|
|
|
$this->app->register($providerClass);
|
|
|
|
|
}
|
2026-01-26 10:37:47 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|