fix: 🐛 Middleware blocca solo le routes GET
This commit is contained in:
parent
36f7299e8b
commit
2f7c341317
|
@ -4,6 +4,7 @@ namespace App\Http\Middleware;
|
|||
|
||||
use App\Models\User;
|
||||
use Closure;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
@ -11,16 +12,26 @@ use Illuminate\Support\Facades\DB;
|
|||
|
||||
class CheckConfigurationMiddleware
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response|RedirectResponse
|
||||
public function handle(Request $request, Closure $next): Response|RedirectResponse|JsonResponse
|
||||
{
|
||||
$checks = [
|
||||
empty(DB::connection()->getDatabaseName()) => 'setup.index',
|
||||
empty(User::exists()) => 'setup.admin',
|
||||
empty(DB::connection()->getDatabaseName()) => [
|
||||
'redirect' => 'setup.index',
|
||||
'patterns' => [
|
||||
'setup.index',
|
||||
'setup.test',
|
||||
'setup.save',
|
||||
],
|
||||
],
|
||||
empty(User::exists()) => [
|
||||
'redirect' => 'setup.admin',
|
||||
'patterns' => 'setup.admin*',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($checks as $check => $route) {
|
||||
if ($check) {
|
||||
return $request->routeIs($route) ? $next($request) : redirect()->route($route);
|
||||
return $request->routeIs($route['patterns']) ? $next($request) : redirect()->route($route['redirect']);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue