Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

christian_H's avatar

Method "redirect" does not exist in \App\Exceptions\Handler.php

When my application throws a TokenMismatchException (generally from me leaving the login screen open too long and then trying to login after the session expired), I end up getting this exception right after:

BadMethodCallException in Macroable.php line 81:
Method redirect does not exist.

It seems that when the TokenMismatchException is being handled by the render() method in Handler.php, the redirect in that method is failing. Here's the code below:

/**
     * Render an exception into an HTTP response.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $e
     * @return \Illuminate\Http\Response
     */
    public function render($request, Exception $e)
    {
       if($e instanceof TokenMismatchException){
        
           return response()->redirect('/login'); //here is the redirect that is causing my headaches
       }

        return parent::render($request, $e);

    }

I'm running Laravel 5.2 and have not modified this file, so it seems odd that this isn't working... anyone encountered this before, and have a solution to fixing it? Thanks very much

0 likes
1 reply
tykus's avatar
tykus
Best Answer
Level 104

Just redirect, not response()->redirect()

return redirect('/login');
1 like

Please or to participate in this conversation.