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

bwrigley's avatar

Session Messages and Page Redirects

currently if someone visits mydomain.com/login they hit this entry in my web.php

Route::get('login', 'Auth\SessionController@showLoginForm')->name('login');

showLoginForm tests to see if they are already authenticated and shows a logged in page or sends them to a simple login form which is submits to:

Route::post('login', 'Auth\SessionController@authenticateUser');

My authenicateUser method, tests authentication and then:

return back()->with(['messages' => $messages]);

which sends the user back to /login where they are either redirected to logged in page (if authentication was successful) or shown the login form again but with errors. This all works fine as is.

But now I need something more sophisticated so I have changed:

return back()->with(['messages' => $messages]);

to

return redirect()->route('login')->with(['messages', $messages]);

and the form is shown but the messages are not.

Is there something I am missing?

0 likes
3 replies
Snapey's avatar
Snapey
Best Answer
Level 122

use the same syntax as before

you have

with(['messages', $messages]);

change to

with(['messages' => $messages]);
1 like
web-chiru's avatar

Try this way too,

return redirect()->route('login')->withMessages($messages);
1 like
bwrigley's avatar

oh my goodness. How embarrassing! Thank you.

Please or to participate in this conversation.