From b6346615e5ae8de08a1f5096a1b8cf8edd010711 Mon Sep 17 00:00:00 2001 From: Georges KABBOUCHI Date: Fri, 22 Nov 2019 12:20:29 +0200 Subject: [PATCH] Add the ability to disable routes --- config/nova-impersonate.php | 4 ++++ src/ToolServiceProvider.php | 24 ++++++++++++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/config/nova-impersonate.php b/config/nova-impersonate.php index 4d49f4f..1404cca 100644 --- a/config/nova-impersonate.php +++ b/config/nova-impersonate.php @@ -18,6 +18,10 @@ * To inject the 'nova-impersonate::reverse' view in every route when impersonating */ 'enable_middleware' => true, + /* + * Enable nova routes + */ + 'enable_routes' => true, /* * false (nova path), true or */ diff --git a/src/ToolServiceProvider.php b/src/ToolServiceProvider.php index 3b16b83..096b049 100644 --- a/src/ToolServiceProvider.php +++ b/src/ToolServiceProvider.php @@ -17,15 +17,17 @@ class ToolServiceProvider extends ServiceProvider */ public function boot() { - Nova::script('nova-impersonate', __DIR__.'/../dist/js/field.js'); - Nova::style('nova-impersonate', __DIR__.'/../dist/css/field.css'); + Nova::script('nova-impersonate', __DIR__ . '/../dist/js/field.js'); + Nova::style('nova-impersonate', __DIR__ . '/../dist/css/field.css'); - $this->loadViewsFrom(__DIR__.'/../resources/views', 'nova-impersonate'); + $this->loadViewsFrom(__DIR__ . '/../resources/views', 'nova-impersonate'); - $this->publishes([__DIR__.'/../resources/views' => base_path('resources/views/vendor/nova-impersonate'), + $this->publishes([ + __DIR__ . '/../resources/views' => base_path('resources/views/vendor/nova-impersonate'), ], 'nova-impersonate-views'); - $this->publishes([__DIR__.'/../config/nova-impersonate.php' => config_path('nova-impersonate.php'), + $this->publishes([ + __DIR__ . '/../config/nova-impersonate.php' => config_path('nova-impersonate.php'), ], 'nova-impersonate-config'); $this->app->booted(function () { @@ -51,10 +53,12 @@ protected function routes() return; } - Route::middleware(Arr::wrap(config('nova-impersonate.middleware.base'))) - ->prefix('nova-impersonate') - ->name('nova.impersonate.') - ->group(__DIR__.'/../routes/api.php'); + if (config('nova-impersonate.enable_routes', true)) { + Route::middleware(Arr::wrap(config('nova-impersonate.middleware.base'))) + ->prefix('nova-impersonate') + ->name('nova.impersonate.') + ->group(__DIR__ . '/../routes/api.php'); + } } /** @@ -64,6 +68,6 @@ protected function routes() */ public function register() { - $this->mergeConfigFrom(__DIR__.'/../config/nova-impersonate.php', 'nova-impersonate'); + $this->mergeConfigFrom(__DIR__ . '/../config/nova-impersonate.php', 'nova-impersonate'); } }