Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

davy_yg's avatar
Level 27

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>
0 likes
7 replies
AddWebContribution's avatar

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>
1 like
davy_yg's avatar
Level 27

includes/flash.blade.php

@if ($message = Session::get('flash'))  
<div class="alert alert-info">  
<ul>
        {{ $message }}
</ul>
</div>
@endif
knubbe82's avatar

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
Vilfago's avatar

I guess you need an animation before using delay

$(document).ready(function(){
          $(".alert").slideDown(300).delay(5000).slideUp(300);
    });
});
1 like
vajid's avatar

do you have alert class inside flash blade?

Vilfago's avatar

Sometimes slideUp has a strange behavior. You can try to replace it by hide(), to see if it works.

Snapey's avatar

Check browser console for javascript errors

Please or to participate in this conversation.