In Laravel < 5.5
I could change this file app/Exceptions/Handler
to change the unauthenticated user redirect url:
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}
return redirect()->guest(route('login'));
}
But in Laravel 5.5
this has been moved to this location vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php
so how can I change it now? I don't want to change stuff in the vendor directory encase it gets overridden by composer updates.
protected function unauthenticated($request, AuthenticationException $exception)
{
return $request->expectsJson()
? response()->json(['message' => 'Unauthenticated.'], 401)
: redirect()->guest(route('login'));
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…