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

thesimons's avatar

Is redirect()->route('route') equal to redirect()->back()?

Hello,

In the controller function that handles a form submission, if I want to send the visitor to the same form page should I use

return redirect()->back();

or

return redirect()->route('route');

With return redirect()->back(); I noticed that the form is subjected to error 419 (classic issue with expired CSRF.

What do you suggest to use in this scenario?

Thanks, Simon

0 likes
1 reply
Jsanwo64's avatar
  1. Difference between redirect()->back()and redirect()->route('route')

redirect()->back()

Redirects to the previous URL (taken from the HTTP Referer header).

Used for when you want to send the user back to wherever they came from (like a “Cancel” button).

redirect()->route('route')

Redirects to a specific named route.

Used for when you know exactly which page to go to (e.g., back to the form page).

Why you’re getting 419 Page Expired with redirect()->back()

This happens because:

redirect()->back() returns the user to the previous request URL, which might be the same POST request (the one that submitted the form).

That means the browser might try to re-POST the form data (without a valid CSRF token anymore).

Hence, Laravel throws a 419 CSRF Token Mismatch error.

Essentially:

You’re redirecting back to the same POST route instead of the GET route of the form.

Correct Approach

return redirect()->route('your.form.route.name');

or better still

// routes/web.php
Route::get('/contact', [ContactController::class, 'showForm'])->name('contact.form');
Route::post('/contact', [ContactController::class, 'submitForm'])->name('contact.submit');

// ContactController.php
public function submitForm(Request $request)
{
    $request->validate([
        'email' => 'required|email',
        'message' => 'required',
    ]);

    // Handle the form...

    return redirect()
        ->route('contact.form')
        ->with('success', 'Thank you for your message!');
}

Please or to participate in this conversation.