Friday, March 4, 2022

[FIXED] Session flash message timeout in Laravel

Issue

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>

Solution

Try this using Jquery function

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

});


Answered By - Kiran Patel

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.