In my controller, I am trying to redirect back using a Flash message in laravel 5. All this works fine. The problem is how I installed it, the flash message always appears again if I move, and then return using the browser's back button.
So, I have a list of users with a delete button next to each user. When I click the delete button, it calls my controller method to destroy. I made a small condition that redirects back with an error if I try to remove the owner. I tried the following different redirection methods, but in doing so I end up with the same problem that the message reappears after navigation and return through the browser back button.
1
return Redirect::route('users')->with('error_message', 'Some error msg');
2
Session::flash('error_message', 'Some error msg'); return Redirect::to('users');
In my opinion, I select it like this:
@if (Session::has('error_message')) {{ Session::get('error_message') }} @endif
So this works well, I get a message. But as soon as, for example, I click a user in my list of users to go to the details page and click the back button of the browser, the message will begin to flash again. I donβt understand why it keeps blinking with this data, I got the impression that it just blinks once.
Even if I try to clear it immediately after the display (for example, below), it does not matter, will it always be displayed again?
{!! Session::forget('error_message') !!}
source share