Hide flash message
How to hide flash message?
I wonder what's missing? I waited for along time and the message still stays there.
<head>
<!-- bootstrap -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> </script>
</head>
...
@include('includes.flash')
...
<script>
$(document).ready(function(){
$(".alert").delay(5000).slideUp(300);
});
</script>
You should try this:
<head>
<!-- bootstrap -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> </script>
</head>
...
<!-- @include('includes.flash') -->
...
<script>
$(document).ready(function(){
$(".alert").delay(5000).slideUp(300);
});
</script>
includes/flash.blade.php
@if ($message = Session::get('flash'))
<div class="alert alert-info">
<ul>
{{ $message }}
</ul>
</div>
@endif
You can also pass type of alert from controller
@foreach (['danger', 'warning', 'success', 'info'] as $msg)
@if(Session::has('alert-' . $msg))
<div id="flash-message" class="alert alert-{{ $msg }}" role="alert">
{{ Session::get('alert-' . $msg) }}
</div>
@endif
@endforeach
I guess you need an animation before using delay
$(document).ready(function(){
$(".alert").slideDown(300).delay(5000).slideUp(300);
});
});
do you have alert class inside flash blade?
Sometimes slideUp has a strange behavior. You can try to replace it by hide(), to see if it works.
Check browser console for javascript errors
Please or to participate in this conversation.