在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