Session flash message remains when going back using browser I've been using this code to display a message:
@if (Session::has('message'))
<div id="welkomBericht">
{{ Session::get('message')}}
</div>
@endif
After clicking away from the page and returning to it using the back button of the browser, the message appears again.
I'm using the flash method of Session. Can I change this behavior?
Thx
try this with jquery . import jquery in head section of your template
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
@if (Session::has('message'))
<div id="welkomBericht" class="fade-message">
{{ Session::get('message')}}
</div>
<script>
$(function(){
setTimeout(function() {
$('.fade-message').slideUp();
}, 5000);
});
</script>
@endif
You can use flash method (Data stored in the session using this method will only be available during the subsequent HTTP request, and then will be deleted):
$request->session()->flash('status', 'Task was successful!');
In your view, use this :
@if (session('status'))
<div class="alert alert-success">
<strong>{{ session('status') }}</strong>
</div>
@endif
Please sign in or create an account to participate in this conversation.