Skip to content
Merged

Dev #3344

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions app/Http/Middleware/EnsureNovaMainDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@ class EnsureNovaMainDashboard
*/
public function handle(Request $request, Closure $next): Response
{
if (! $this->isNovaDashboardRequest($request)) {
return $next($request);
self::ensureMainDashboardRegistered($request);

return $next($request);
}

/**
* Call from anywhere (e.g. web middleware) to ensure Main dashboard exists for Nova paths.
*/
public static function ensureMainDashboardRegistered(Request $request): void
{
$path = $request->path();
$isNova = $path === 'nova' || str_starts_with($path, 'nova/') || str_starts_with($path, 'nova-api/');
if (! $isNova) {
return;
}

$hasMain = collect(Nova::$dashboards)->contains(function ($dashboard) {
Expand All @@ -31,8 +43,6 @@ public function handle(Request $request, Closure $next): Response
if (! $hasMain) {
Nova::dashboards([new Main]);
}

return $next($request);
}

private function isNovaDashboardRequest(Request $request): bool
Expand Down
4 changes: 2 additions & 2 deletions app/Nova/GirlsInDigitalFaqItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public static function authorizedToCreate(Request $request): bool
return true;
}

public static function authorizedToUpdate(Request $request, $model): bool
public function authorizedToUpdate(Request $request): bool
{
return true;
}

public static function authorizedToDelete(Request $request, $model): bool
public function authorizedToDelete(Request $request): bool
{
return true;
}
Expand Down
12 changes: 12 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Arr;
use Illuminate\Support\ServiceProvider;
Expand Down Expand Up @@ -155,6 +156,17 @@ function ($view) {

$this->bootAuth();
$this->bootEvent();
$this->bootNovaMainDashboardRoute();
}

/**
* Ensure /nova/dashboards/main always has a matching route (no domain constraint).
*/
protected function bootNovaMainDashboardRoute(): void
{
Route::middleware(config('nova.middleware', []))
->get('/nova/dashboards/main', [\Laravel\Nova\Http\Controllers\Pages\DashboardController::class, '__invoke'])
->defaults('name', 'main');
}

/**
Expand Down
1 change: 1 addition & 0 deletions bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
]);

$middleware->web([
\App\Http\Middleware\EnsureNovaMainDashboard::class,
\App\Http\Middleware\CheckBrowser::class,
\App\Http\Middleware\Locale::class,
\App\Http\Middleware\CheckConsent::class
Expand Down
Loading