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

chriz74's avatar

How to Flash messages in same page without redirecting?

Does anyone know how to do this? If I remove the redirect from the code I will only get a blank page.

Session::flash('message', "my message");
return Redirect::back();
0 likes
11 replies
chriz74's avatar

dismiss this, I am returning my view instead or redirecting and it works.

tang.chanrith's avatar

You can do that by using "now($key, $value)"

session()->now('message', 'Success! message.');
secondman's avatar

@tang.chanrith

I see this in the Store class, and I'm trying to use if but it's not working.

session()->now('success', 'The client was updated successfully.');

Nothing at all. I also tried:

session()->now('success', 'The client was updated successfully.');
session()->reflash();

No love on flash at all without a redirect, I'm using Inertia so there's no redirect here.

1 like
Snapey's avatar

@vkronlein if you want help, start a new question, not add to a three year old one that is not even related to your issue

secondman's avatar

@snapey

How is it not related? I'm having this exact problem, I need to flash on an existing page.

This question has no answer yet ... no reason to open a new one, I searched and found this open one.

Sorry if this isn't the proper way, I'm used to SO where you get hammered for not searching to find the answers before you open a new question.

Snapey's avatar

I doubt the three year old question was related to inertia. In your case it is critical to your problem.

@vkronlein

secondman's avatar

@snapey

Flashing a message without redirecting is not an Inertia issue. It's a Laravel issue. I only wrote that I was using Inertia as an aside in hopes it might lead to a faster resolution. Though using Inertia did lead to a much faster and simpler answer.

But thank you for hopping in here and helping with the issue.

.... oh wait ....

Snapey's avatar

Flashing a message requires that the blade view is rendered. You render a view in response to a get request.

php session data cannot just magically appear in the client.

The original question was answered by the OP himself if you check above.

technoigniters's avatar

`use Session;

Session::flash('message', "my message");

return Redirect::back();`

technoigniters's avatar

getting error Redirect not found, I am using Laravel 11.x version. Thanks.

Please or to participate in this conversation.