Sweet Alert flash notifications in Laravel.

Installs: 1 786

Dependents: 2

Suggesters: 0

Stars: 0

Watchers: 1

Forks: 1

Open Issues: 0

Type:project

v1.0.1 2019-04-05 15:13 UTC

README

Installation

Note: This installation assumes you've already included Sweet Alert in your html layout.

Require flash in your composer.json file:

"stevebauman/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.');