Package Data | |
---|---|
Maintainer Username: | riazXrazor |
Maintainer Contact: | riazcool77@gmail.com (Riaz Laskar) |
Package Create Date: | 2017-02-26 |
Package Last Update: | 2018-03-02 |
Language: | JavaScript |
License: | MIT |
Last Refreshed: | 2024-11-20 03:03:17 |
Package Statistics | |
---|---|
Total Downloads: | 1,014 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 2 |
Total Watchers: | 3 |
Total Forks: | 2 |
Total Open Issues: | 0 |
Laravel package to show beautiful flash message.
Its basically a laravel wrapper for the beautiful
and very good and useful jquery plugin
SweetAlert2
.
Using SweetAlert2 : 7.13.0
Open composer.json
and add this line below.
{
"require": {
"riazxrazor/laravel-sweet-alert": "^1.2.0"
}
}
Or you can run this command from your project directory.
composer require riazxrazor/laravel-sweet-alert
Open the config/app.php
and add this line in providers
section.
Riazxrazor\LaravelSweetAlert\LaravelSweetAlertServiceProvider::class,
add this line in the aliases
section.
'LaravelSweetAlert' => Riazxrazor\LaravelSweetAlert\LaravelSweetAlert::class
Publish public assets
by running this command.
php artisan vendor:publish --tag=public --force
Place this blade directive at the end before </body>
section of the html of
layout blade template
@LaravelSweetAlertJS
You can use the function like this.
// in the controller method
\LaravelSweetAlert::setMessageSuccess("flash message")
\LaravelSweetAlert::setMessageError("error flash message")
\LaravelSweetAlert::setMessageSuccessConfirm("flash message")
\LaravelSweetAlert::setMessageErrorConfirm("error flash message")
// for more customization
LaravelSweetAlert::setMessage([
'title' => 'Successful',
'text' => $text,
'timer' => 2000,
'type' => 'success',
'showConfirmButton' =>false
]);
\LaravelSweetAlert::setMessage([
'title' => 'Auto close alert!',
'text' => 'I will close in 5 seconds.',
'timer' => 5000,
'onOpen' => '() => { swal.showLoading() }',
],
// second argument array of js function each element will be a then to swal
['(result) => {
if (
// Read more about handling dismissals
result.dismiss === swal.DismissReason.timer
) {
console.log("I was closed by the timer")
}
}'],
// third argument is a catch function to the promise of swal
'(e)=>console.log(e)');
when the when is redirected to another route a beautiful flash message appears
for more customization options please refer to
SweetAlert2
, just pass the js object as associative array in the
setMessage
method.