Предположим, у меня есть этот маршрут:
Код: Выделить всё
Route::get('/tasks/{task}/apply/', [ApplicationController::class, 'create'])
->middleware('auth')
->name('applications.create');
В моем контроллере я вызываю политику:
Код: Выделить всё
public function create(Task $task)
{
Gate::authorize('create', [Application::class, $task]);
}
Код: Выделить всё
public function create(User $user, Task $task): Response
{
return Response::deny('You are not allowed to apply to this task.');
}
Код: Выделить всё
/**
* Handle an incoming authentication request.
*/
public function store(LoginRequest $request): RedirectResponse
{
$request->authenticate();
$request->session()->regenerate();
return redirect()->intended(AppServiceProvider::HOME);
}
- Я получаю перенаправлен на страницу входа
- Вход с правильными учетными данными
- Меня перенаправляют обратно на ожидаемый маршрут
- Поскольку политика отклоняет мой запрос, вместо фактической страницы отображается страница с ошибкой 403.
- Меня перенаправляют на страницу входа (как и ожидалось)
- Войдите в систему, используя правильные учетные данные
- Адресная строка моего браузера по-прежнему является URL-адресом входа в систему.
- Открывается модальное окно, и внутри модального окна отображается страница с ошибкой 403 (без перенаправления на намеченный маршрут).
В инструментах разработчика Chrome это мои запросы:
Код: Выделить всё
Request-Url:
http://127.0.0.1:8000/tasks/9c659414-220d-427a-ab16-3fea3a76fdcd/apply
Request-Method:
GET
Statuscode:
302 Found
Remote-Address:
127.0.0.1:8000
Guidelines for referrer URL:
strict-origin-when-cross-origin
Код: Выделить всё
Location: http://127.0.0.1:8000/loginКод: Выделить всё
Request-URL:
http://127.0.0.1:8000/login
Request-Method:
GET
Statuscode:
200 OK
Remote-Address:
127.0.0.1:8000
Guidelines for referrer URL:
strict-origin-when-cross-origin
Код: Выделить всё
Request-URL:
http://127.0.0.1:8000/login
Request-Method:
POST
Statuscode:
302 Found
Remote-Address:
127.0.0.1:8000
Guidelines for referrer URL:
strict-origin-when-cross-origin
Код: Выделить всё
Location: http://127.0.0.1:8000/tasks/9c659414-220d-427a-ab16-3fea3a76fdcd/applyКод: Выделить всё
Request-URL:
http://127.0.0.1:8000/tasks/9c659414-220d-427a-ab16-3fea3a76fdcd/apply
Request-Method:
GET
Statuscode:
403 Forbidden
Remote-Address:
127.0.0.1:8000
Guidelines for referrer URL:
strict-origin-when-cross-origin
Дополнительная информация:
- Laravel Версия: 11.14.0
- Версия PHP: 8.2.4
- @inertiajs/vue3 Версия: 1.2.0
Подробнее здесь: https://stackoverflow.com/questions/787 ... ia-laravel
Мобильная версия