An easy way for Laravel flash notifications using sweetalert JS plugin.

v1.0.0 2016-10-06 05:54 UTC

This package is auto-updated.

Last update: 2024-05-04 15:40:27 UTC


Build Status

Laravel alert notifications using a beautiful javascript alert (sweet-alert).


Install via composer

$ composer require squareboat/alert

Configure Laravel

Once installation operation is complete, simply add both the service provider and facade classes to your project's config/app.php file:

Service Provider



'Alert' => SquareBoat\Alert\Facades\Alert::class,

Download & install Sweet Alert library

Download the .js and .css from the website


Install through bower

bower install sweetalert


Install through NPM:

npm install sweetalert

Finally, include default alert view to your layout

Package default provides bootstrap ready alert view. Just include alert::message file to your main layout in blade:


or if you don't use blade:

<?= view('alert::message') ?>

If you need to modify the alert message partials, you can run:

php artisan vendor:publish

The package view will now be located in the resources/views/vendor/alert directory.

And that's it! With your coffee in reach, start flashing out alert messages!


Within your controllers, before you perform a redirect...

public function create()
    // do something awesome...

    alert()->success('Resource created successfully!');

    return redirect()->route('dashboard');

Level for all alerts are following:


Alert::success('This is a success message.', 'Optional Title');


alert()->success('This is a success message.', 'Optional Title');


Alert::basic('This is a basic message.', 'Mandatory Title');


alert()->basic('This is a basic message.', 'Mandatory Title');


Alert::info('This is an info message.', 'Optional Title');


alert()->info('This is an info message.', 'Optional Title');


Alert::warning('This is a warning message.', 'Optional Title');


alert()->warning('This is a warning message.', 'Optional Title');


Alert::error('This is an error message.', 'Optional Title');


alert()->error('This is an error message.', 'Optional Title');

Default View

<?php if(session()->has('sweet_alert.alert')) { ?>
        if (typeof swal === "function") {
            swal(<?= e(session('sweet_alert.alert')) ?>);
        } else {
            sweet_alert = <?= e(session('sweet_alert.alert')) ?>;
<?php } ?>

The sweet_alert.alert session key contains a JSON configuration object to pass it directly to Sweet Alert swal() funtion.

Default view considers that you have initialized the sweetalert plugin by referencing the necessary files and uses its swal() function.

If swal() function is not defined then default view declares a javascript variable sweet_alert which you can use anywhere you like.

Final Considerations

By default, all alerts will dismiss after a sensible default number of seconds. But no fear, if you need to specify a different time you can:

alert('Some alert message!')->autoclose(2000);

Remember!, the number is set in milliseconds

Also, if you need the alert to be persistent on the page until the user dismiss it by pressing the alert confirmation button:

alert('Force may with you')->important("optional text");

The optional text will appear in the button otherwise default text OK is shown.


The MIT License. Please see License File for more information. Copyright © 2016 SquareBoat