diff --git a/config/adminlte.php b/config/adminlte.php index 21c40961..727a0018 100644 --- a/config/adminlte.php +++ b/config/adminlte.php @@ -264,6 +264,7 @@ 'password_reset_url' => 'password/reset', 'password_email_url' => 'password/email', 'profile_url' => false, + 'disable_darkmode_routes' => false, /* |-------------------------------------------------------------------------- diff --git a/routes/web.php b/routes/web.php index 624c5670..34f9b948 100644 --- a/routes/web.php +++ b/routes/web.php @@ -18,5 +18,7 @@ // Dark Mode routes. //----------------------------------------------------------------------------- -Route::post('/darkmode/toggle', [DarkModeController::class, 'toggle']) - ->name('darkmode.toggle'); +if (! config('adminlte.disable_darkmode_routes', false)) { + Route::post('/darkmode/toggle', [DarkModeController::class, 'toggle']) + ->name('darkmode.toggle'); +} diff --git a/tests/ServiceProviderTest.php b/tests/ServiceProviderTest.php index 4dae482e..f176a5fc 100644 --- a/tests/ServiceProviderTest.php +++ b/tests/ServiceProviderTest.php @@ -1,6 +1,7 @@ assertTrue(isset($aliases['adminlte-modal'])); } - public function testBootLoadRoutes() + public function testBootLoadDarkModeRoutes() { - // Assert the package routes names are registered. + // Disable dark mode routes and check. + + config(['adminlte.disable_darkmode_routes' => true]); + $this->clearRoutesAndReRegisterProvider(); + + $this->assertFalse(Route::has('adminlte.darkmode.toggle')); + + // Enable dark mode routes and check again. + + config(['adminlte.disable_darkmode_routes' => false]); + $this->clearRoutesAndReRegisterProvider(); $this->assertTrue(Route::has('adminlte.darkmode.toggle')); } + + /** + * Clear routes and re-register the service provider. + */ + protected function clearRoutesAndReRegisterProvider() + { + // Clear the current route collection. + + Route::setRoutes(new \Illuminate\Routing\RouteCollection()); + + // Unregister and register the provider again. + + $provider = $this->app->register(AdminLteServiceProvider::class); + $provider->boot(); + + // Refresh route names after loading routes again. + + Route::getRoutes()->refreshNameLookups(); + } }