0
votes

I'm making an application in Laravel. When using Session::flash to display a message, the Session lasts for two requests (ie the page loads successfully with the message, then when I refresh, it's still there. When I refresh again, it disappears). Here is the code to create the Session and call the view:

Session::flash('status', "We are processing refunds for this event. If you are due refunds, check back in 24h.");
view('voucher.index', compact('events', 'orders'));

Any views on this are appreciated!

2
How are you displaying this flash message in the view?Rafael Berro
'@if (Session::has('status')) <div class="alert alert-danger">{{ Session::get('status') }}</div> @'frostfat
In a blade.php filefrostfat
@frostfat this may help you. stackoverflow.com/questions/23958038/…Manish

2 Answers

1
votes

You should not be returning a view after the action you are doing like that. You should be returning a redirect to a GET route where you will be displaying that view instead.

try this approach: return redirect()->route(...)->with('success', ....);

1
votes

Use now instead of flash

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