riazxrazor/laravel-sweet-alert

Laravel package to show beautiful flash message

Installs: 1 014

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 3

Forks: 2

Open Issues: 0

Language:JavaScript

1.2.1 2018-03-02 04:17 UTC

README

GitHub Author GitHub release GitHub license GitHub issues

StyleCI

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

Installation

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

Configuration

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

Usage

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.