在Laravel < 5.5
我可以改變這個文件app/Exceptions/Handler
改變未經身份驗證的用戶重定向URL:Laravel 5.5改變未經驗證的登錄重定向URL
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}
return redirect()->guest(route('login'));
}
但Laravel 5.5
這已被移動到這個位置vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php
所以我能怎樣改變現在?我不想更改供應商目錄中的東西,並且它會被作曲者更新覆蓋。
protected function unauthenticated($request, AuthenticationException $exception)
{
return $request->expectsJson()
? response()->json(['message' => 'Unauthenticated.'], 401)
: redirect()->guest(route('login'));
}
https://laravel-news.com/custom-exception-reporting我發現了這個 –
所以你可以捕獲身份驗證錯誤,然後在被laravels抓住之前重定向。非常感謝 – robertmylne
@robertmylne工作嗎?因爲這個解決方案只是爲了報告! – Maraboc