New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

jeremy379/flash

Easy flash notifications with multiple messages
15,315
Install
composer require jeremy379/flash
Latest Version:v2.7
PHP:>=7.4.0
Laravel:8
Older releases:5
License:MIT
Last Updated:Oct 12, 2020
Links: GitHub  ·  Packagist
Maintainer: jeremy379
  • Forked at first from Laracasts/Flash to use multiple message and then forked from mdupaul/flash

Easy Flash Messages

Installation

First, pull in the package through Composer.

Run composer require jeremy379/flash

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

'providers' => [
    'Jeremy379\Flash\FlashServiceProvider'
];

And, for convenience, add a facade alias to this same file at the bottom:

'aliases' => [
    'Flash' => 'Jeremy379\Flash\Flash'
];

Usage

Within your controllers, before you perform a redirect...

public function store()
{
    Flash::message('Welcome Aboard!');

    return Redirect::home();
}

You may also do:

  • Flash::info('Message')
  • Flash::success('Message')
  • Flash::error('Message')
  • Flash::warning('Message')
  • Flash::overlay('Modal Message', 'Modal Title')

Again, if using Laravel, this will set a few keys in the session:

  • 'flash_notification.message' - The message you're flashing
  • 'flash_notification.level' - A string that represents the type of notification (good for applying HTML class names)

Alternatively, again, if you're using Laravel, you may reference the flash() helper function, instead of the facade. Here's an example:

/**
 * Destroy the user's session (logout).
 *
 * @return Response
 */
public function destroy()
{
    Auth::logout();

    flash()->success('You have been logged out.');

    return home();
}

Or, for a general information flash, just do: flash('Some message');.

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

@if (Session::has('flash_notification.message'))
    <div class="alert alert-{{ Session::get('flash_notification.level') }}">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>

        {{ Session::get('flash_notification.message') }}
    </div>
@endif

Note that this package is optimized for use with Twitter Bootstrap.

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:

@include('flash::message')

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

660,512,042 9,702
laravel/framework

The Laravel Framework.

625,568,548 34,998
laravel/tinker

Powerful REPL for the Laravel framework.

531,591,559 7,442
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

450,320,528 608
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

418,503,470 4,663

Version History

Version Released PHP Laravel License
v2.7 >=7.4.0 >8.0 MIT
v2.6 >=7.4.0 >8.0 MIT
v2.3 >=7.4.0 >8.0 MIT
v2.2 >=7.4.0 >8.0 MIT
v2.1 >=7.4.0 >8.0 MIT