Skip to content
Advertisement

Session flash message timeout in Laravel

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>

Advertisement

Answer

Try this using Jquery function

$("document").ready(function(){
    setTimeout(function(){
       $("div.alert").remove();
    }, 5000 ); // 5 secs

});
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement