nashultz / flash
Sweet Alert flash notifications in Laravel.
v1.0.3
2020-06-24 02:18 UTC
Requires
- php: >=7.2.5
- laravel/framework: ^7.0
Requires (Dev)
- orchestra/testbench: ~5.3
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2024-10-24 16:47:16 UTC
README
Installation
Note: This installation assumes you've already included Sweet Alert in your html layout.
Require flash
in your composer.json
file:
"nashultz/flash": "1.0.*",
Then run composer update
.
Now create a partial blade file (maybe resources/views/_flash.blade.php
?), and insert the following:
@if(session()->has('flash_message')) <script type="text/javascript"> swal({ title: "{!! session('flash_message.title') !!}", text: "{!! session('flash_message.message') !!}", type: "{!! session('flash_message.level') !!}", @if(session('flash_message.timer')) timer: "{!! session('flash_message.timer') !!}" @endif }); </script> @endif
Your all set!
Usage
Call the flash()
helper method like so:
flash()->create($title = 'Custom', $message = 'Message Content', $level = 'info'); flash()->success('Success!', "You've successfully done something, congrats!"); flash()->info('Info!', "Just letting you know something informative."); flash()->warning('Warning!', 'Hey watch out, somethings going on!'); flash()->error('Error!', "Uh oh, there was an error doing something!");
Setting an automatic timeout of the notification:
Note, by default notifications have a 2 second timeout.
flash()->setTimer(5000)->success('Success!', 'This notification will disappear in five seconds.');