From 04f26f6f0200a7ac27c1f9f64f503bc2e29f2495 Mon Sep 17 00:00:00 2001 From: bernardhanna Date: Wed, 11 Feb 2026 15:56:52 +0000 Subject: [PATCH] dynamic GID --- .../Middleware/EnsureNovaMainDashboard.php | 47 +++++++++++++++++++ config/nova.php | 1 + 2 files changed, 48 insertions(+) create mode 100644 app/Http/Middleware/EnsureNovaMainDashboard.php diff --git a/app/Http/Middleware/EnsureNovaMainDashboard.php b/app/Http/Middleware/EnsureNovaMainDashboard.php new file mode 100644 index 000000000..e942aa2a9 --- /dev/null +++ b/app/Http/Middleware/EnsureNovaMainDashboard.php @@ -0,0 +1,47 @@ +isNovaDashboardRequest($request)) { + return $next($request); + } + + $hasMain = collect(Nova::$dashboards)->contains(function ($dashboard) { + return $dashboard->uriKey() === 'main'; + }); + + if (! $hasMain) { + Nova::dashboards([new Main]); + } + + return $next($request); + } + + private function isNovaDashboardRequest(Request $request): bool + { + $path = $request->path(); + + return $path === 'nova/dashboards/main' + || str_starts_with($path, 'nova/dashboards/') + || $path === 'nova-api/dashboards/main' + || str_starts_with($path, 'nova-api/dashboards/'); + } +} diff --git a/config/nova.php b/config/nova.php index 7ff8702b9..0f115c67c 100644 --- a/config/nova.php +++ b/config/nova.php @@ -75,6 +75,7 @@ 'web', HandleInertiaRequests::class, DispatchServingNovaEvent::class, + \App\Http\Middleware\EnsureNovaMainDashboard::class, BootTools::class, ],