nashultz/flash

Sweet Alert flash notifications in Laravel.

Maintainers

Details

github.com/nashultz/flash

Source

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 2

Type:project

v1.0.3 2020-06-24 02:18 UTC

This package is auto-updated.

Last update: 2020-06-24 02:22:53 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.');