check()) { return redirect()->guest(route('login')) ->with('error', 'Log eerst in met je beheerder-account om toegang te krijgen tot het admin gedeelte.'); } if (! auth()->user()->isAdmin()) { return redirect()->route('home') ->with('error', 'Je hebt geen beheerderstoegang tot deze pagina.'); } // Auto-migrate check: Ensure that new database tables (like communications) are migrated // automatically when an admin enters the admin panel, avoiding 500 errors on Coolify/production. try { if (! Schema::hasTable('communications')) { Artisan::call('migrate', ['--force' => true]); } } catch (\Throwable $e) { Log::warning('Auto-migration in EnsureUserIsAdmin failed: '.$e->getMessage()); } return $next($request); } }