Fix 500 error on admin access: make navigation layout resilient and auto-run pending migrations on admin entry

This commit is contained in:
2026-11-02 10:38:22 +01:00
parent 44c440222a
commit cf55f3c9f9
7 changed files with 76 additions and 9 deletions
+13
View File
@@ -4,6 +4,9 @@ namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Schema;
use Symfony\Component\HttpFoundation\Response;
class EnsureUserIsAdmin
@@ -23,6 +26,16 @@ class EnsureUserIsAdmin
->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);
}
}