For laravel version < 5.5 go to App/Exceptions/handler.php and change this method
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}
return redirect()->guest(route('/'));
}
For laravel 5.5 App/Exceptions/handler.php
<?php
namespace App\Exceptions;
use Exception;
use Request;
use Illuminate\Auth\AuthenticationException;
use Response;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
protected function unauthenticated($request, AuthenticationException $exception)
{
return $request->expectsJson()
? response()->json(['message' => 'Unauthenticated.'], 401)
: redirect()->guest(route('/'));
}
}
How can I do the same thing in Laravel 8? i.e. How can redirect to e.g lsyt/login after the authenticated user session expired. I didn't find this redirect()->guest(route('/')); in App/Exceptions/handler.php. in Laravel 8.
Please help.