Reputation: 7195
I have created flash message in Laravel page using controller. It's showing well but need to add timeout in flash message
if($location_vaidation>0){
$material_details->location_id=$requested_location;
}
else{
Session::flash('success', 'please fill the form with valid data');
return Redirect::to('request');
exit;
}
In view page
@if( Session::has("success") )
<div class="alert alert-success alert-block" role="alert">
<button class="close" data-dismiss="alert"></button>
{{ Session::get("success") }}
</div>
@endif
@if( Session::has("error") )
<div class="alert alert-danger alert-block" role="alert">
<button class="close" data-dismiss="alert"></button>
{{ Session::get("error") }}
</div>
@endif
<div class="flash-message"></div>
Upvotes: 2
Views: 14404
Reputation: 1077
In the header add this:
<script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js"></script>
then use it in blade as following:
@if (session($messageKey))
<div x-data="{show: true}" x-init="setTimeout(() => show = false, 5000)" x-show="show">
<div class="alert alert-success">
{{ session($messageKey) }}
</div>
</div>
@endif
Upvotes: 6
Reputation: 379
Try this using Jquery function
$("document").ready(function(){
setTimeout(function(){
$("div.alert").remove();
}, 5000 ); // 5 secs
});
Upvotes: 8
Reputation: 11491
you might want this to autoclose / fadeout your alert messages, This will be a smooth fading , and you do require jquery
$(".alert").fadeTo(2000, 500).slideUp(500, function(){
$(".alert").slideUp(500);
});
Upvotes: 4