gbuckingham89 / laraflash by gbuckingham89

A package for handling flash messages / notifications in Laravel.
22,040
0
1
Package Data
Maintainer Username: gbuckingham89
Maintainer Contact: george@georgebuckingham.com (George Buckingham)
Package Create Date: 2017-01-18
Package Last Update: 2024-03-23
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-04-22 15:05:26
Package Statistics
Total Downloads: 22,040
Monthly Downloads: 688
Daily Downloads: 29
Total Stars: 0
Total Watchers: 1
Total Forks: 1
Total Open Issues: 0

gbuckingham89/laraflash

A package for handling flash messages / notifications in Laravel.

Developed for Laravel 5.2, but may also work in earlier 5.* versions. The levels of priority for messages and included view are optimised for use with Bootstrap.

Installation

The recommended way is using Composer - simply run this command in your terminal:

composer require gbuckingham89/laraflash

You'll then need to register the service provider by adding the following to the providers array in your app.php config file:

Gbuckingham89\Laraflash\LaraflashServiceProvider::class

You'll also need to register the facade by adding the following to the aliases array in your app.php config file:

'Laraflash' => Gbuckingham89\Laraflash\Laraflash::class 

Finally, you'll need to publish the view file (unless you want to roll your own). Do this by running this command in your terminal:

php artisan vendor:publish --provider="Gbuckingham89\Laraflash\LaraflashServiceProvider"

Use

Setting a message

Before you redirect to another page, simply use the Laraflash facade to set your message. You can call the main flash method as follows:

Laraflash::flash("This is a flash message.", "success");

The first parameter is your message, the second is the priority level.

There are also four helper methods available for easier setting of priority levels:

Laraflash::success("This is a success flash message.");

Laraflash::info("This is an info flash message.");

Laraflash::warning("This is a warning flash message.");

Laraflash::danger("This is a danger flash message.");

Displaying the message

To display the message, simply include the bundled view (built for Bootstrap) in your view:

@include('laraflash::laraflash')

Alternatively, you can access the data in the session directly (stored in laraflash.message and laraflash.level) and roll your own view.

Copyright and license

Code and documentation copyright 2017 George Buckingham. Code released under the MIT License.