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

jonnybarnes's avatar

Where should TokenMismatchException be caught when using L5's route annotations?

This may seem a simple question, but in using the generated AuthController this is my login code:

/**
 * Handle a login request to the application.
 *
 * @Post("auth/login", as="login")
 *
 * @param  LoginRequest  $request
 * @return Response
 */
public function login(LoginRequest $request)
{
    if ($this->auth->attempt($request->only('email', 'password')))
    {
        return redirect('/');
    }

    return redirect()->route('login')->withErrors([
        'email' => 'These credentials do not match our records.',
    ]);
}

Should I add a try catch block around the if-attempt section?

0 likes
0 replies

Please or to participate in this conversation.