The gnahotelsolutions/flasher
package provides an easy way to interact with flashed messages in your Laravel application.
You can install the package via composer:
$ composer require gnahotelsolutions/flasher
The messages are stored in the notifications
session key.
All notifications have a default duration
property set to 5 seconds. You can use this property in your JavaScript to make notifications disappear automatically.
Flasher::info("Welcome, {$user->name}");
Flasher::error('Incorrect password');
Flasher::warning('Remember to change your password');
Flasher::success('Password changed!');
If you want to use custom types, you can use the method createNotification
Flasher::createNotification('store', 'Someone bought a product!', null);
@if (Flasher::any())
<div class="alerts">
...
</div>
@endif
@foreach(Flasher::all() as $notification)
<div class="alert alert-{{ $notification->getType() }}" data-duration="{{ $notification->getDuration() }}">
{{ $notification->getMessage() }}
</div>
@endforeach
If you're using Bootstrap in your project, you can use getBootstrapClass()
method.
It will replace error
with danger
to match the framework's CSS class.
phpunit
If you discover any security related issues, please email dllop@gna.es instead of using the issue tracker.
The MIT License (MIT).