2017 © Pedro Peláez

library laravel-flash-message

Flash Messages made easy. Based on laracasts/flash



Flash Messages made easy. Based on laracasts/flash

  • Wednesday, September 14, 2016
  • by mtxr
  • Repository
  • 1 Watchers
  • 2 Stars
  • 136 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 30 % Grown


Flash messages made easy. Based on laracasts/flash


First, pull in the package through Composer., (*1)

Run composer require mtxr/laravel-flash-message, (*2)

And then, if using Laravel 5, include the service provider within config/app.php., (*3)

'providers' => [


Within your controllers, before you perform a redirect..., (*4)

public function store()
    flash('Welcome Aboard!');

    return home();

You may also do:, (*5)

  • flash('Message', 'info')
  • flash('Message', 'success')
  • flash('Message', 'danger')
  • flash('Message', 'warning')
  • flash('Message')->important()

Adding Icons: - flash('Message')->icon('fa fa-exclamation-circle'), (*6)

Deleting last message: - flash()->delete(), (*7)

Clearing message queue: - flash()->clear(), (*8)

If you need, you can flash two messages in the same request:, (*9)

public function welcome()
    flash('Welcome Aboard!', 'success');

    flash('Request Failed!', 'error');

    return home();

Behind the scenes, this will set a few keys in the session:, (*10)

  • 'flash_notification.messages' - The array of messages you have

With this message flashed to the session, you may now display it in your view(s). Maybe something like:, (*11)

@if (session()->has('flash_notification.messages'))
    @foreach(session('flash_notification.messages') as $messageData)

@if(!$messageData['important']) @endif {!! trans($messageData['message']) !!}
@endforeach @endif

Note that this package is optimized for use with Twitter Bootstrap., (*12)

Because flash messages and overlays are so common, if you want, you may use (or modify) the views that are included with this package. Simply append to your layout view:, (*13)



<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">


Welcome to my website..., (*14)

</body> </html>

If you need to modify the flash message partials, you can run:, (*15)

php artisan vendor:publish

The package view will now be located in the app/views/packages/mtxr/laravel-flash-message/ directory., (*16)

Hiding Flash Messages

A common desire is to display a flash message for a few seconds, and then hide it. To handle this, write a simple bit of JavaScript. For example, using jQuery, you might add the following snippet just before the closing </body> tag., (*17)

<script type="text/javascript">

This will find any alerts - excluding the important ones, which should remain until manually closed by the user - wait three seconds, and then fade them out., (*18)

The Versions

14/09 2016



Flash Messages made easy. Based on laracasts/flash

  Sources   Download


The Requires


The Development Requires

by Matheus