Fix 500 error on admin access: make navigation layout resilient and auto-run pending migrations on admin entry
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user