diff --git a/src/Providers/RoutingServiceProvider.php b/src/Providers/RoutingServiceProvider.php deleted file mode 100644 index 6efa0b2..0000000 --- a/src/Providers/RoutingServiceProvider.php +++ /dev/null @@ -1,18 +0,0 @@ -app->singleton('router', function ($app) { - return new Router($app['events'], $app); - }); - } -} diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 73c96b8..8cc0a41 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -4,6 +4,8 @@ namespace DragonCode\LaravelRouteNames; +use DragonCode\LaravelRouteNames\Routing\Router; +use Illuminate\Routing\Router as BaseRouter; use Illuminate\Support\ServiceProvider as BaseServiceProvider; class ServiceProvider extends BaseServiceProvider @@ -16,6 +18,7 @@ public function boot(): void public function register(): void { $this->registerConfig(); + $this->extendRouter(); } protected function publishConfig(): void @@ -37,4 +40,17 @@ protected function getPath(): string { return __DIR__ . '/../config/route.php'; } + + protected function extendRouter(): void + { + $this->app->booting(function (): void { + $this->app->extend( + 'router', + static fn( + BaseRouter $router, + $app + ): Router => !$router instanceof Router ? new Router($app['events'], $app) : $router + ); + }); + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index a2a009b..f474425 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -17,7 +17,6 @@ namespace Tests; -use DragonCode\LaravelRouteNames\Providers\RoutingServiceProvider; use DragonCode\LaravelRouteNames\ServiceProvider; use Illuminate\Events\EventServiceProvider; use Illuminate\Log\LogServiceProvider; @@ -35,7 +34,6 @@ protected function getPackageProviders($app): array return [ EventServiceProvider::class, LogServiceProvider::class, - RoutingServiceProvider::class, ServiceProvider::class, ]; }