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

Webster.'s avatar

Session flash data

Apparently, the I cannot save data using $request -> session() -> flash() in laravel...

I try:

    $request -> session() -> flash("test", "al!");
    return redirect('checker');

(in controller) and then

Route::get("/checker", function() {
    echo "Session data: ".session('test');
});

(in routes) but nothing is displayed.

0 likes
5 replies
tim_jespers's avatar
Level 3

You're using session()->flash(); Which puts data in the session for the current request only, after that you're redirecting (new request) so the flash is gone. If you want to actually store things in the session use:

session(["key" => "value"); or $request->session()->put('key', 'value');

for more on sessions see the docs

1 like
jimyx's avatar

@tim_jespers Your description is not correct. session()->flash();" Data stored in the session using this method will be available immediately and during the subsequent HTTP request". Not Current request only. "To persist your flash data only for the current request, you may use the now method" : $request-> session()->now('status', 'Task was successful!');

1 like
tim_jespers's avatar

You i totally forgot you can also redirect with flash in that way, thanks for keeping me sharp!

Please or to participate in this conversation.