Scarwolf Scarwolf - 1 year ago 84
PHP Question

Laravel Change Redirection part if the Auth's session expires

When the session expires my users are getting redirected to

however they should be redirected to
, does anyone know in which file I can change the redirection part?

Answer Source

Your Exception Handler is what takes all unauthenticated requests and handles them in the way you need.

It will look something like this:


 * Convert an authentication exception into an unauthenticated response.
 * @param  \Illuminate\Http\Request  $request
 * @param  \Illuminate\Auth\AuthenticationException  $exception
 * @return \Illuminate\Http\Response
protected function unauthenticated($request, AuthenticationException $exception)
    if ($request->expectsJson()) {
        return response()->json(['error' => 'Unauthenticated.'], 401);

    return redirect()->guest('login');

You can adjust the redirect by changing return redirect()->guest('login'); to return redirect()->guest('backoffice/login');

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download