smodav/flash

Flash messaging package for use with laravel

Maintainers

Details

github.com/SmoDav/flash

Source

Issues

Installs: 259

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 2

Forks: 0

Open Issues: 0

Language:CSS

v1.0.1 2016-07-26 11:31 UTC

This package is auto-updated.

Last update: 2024-11-24 19:05:08 UTC


README

Build Status Total Downloads Latest Stable Version Latest Unstable Version License

This is a laravel package for displaying flash notifications that extends Sweet Alert and provides an extra custom notice notification on the top left.

Installation

Pull in the package through Composer.

Run composer require smodav/flash

When using Laravel 5, include the service provider and its alias within your config/app.php.

'providers' => [
    SmoDav\Flash\FlashServiceProvider::class,
];

'aliases' => [
    'Flash' => SmoDav\Flash\Flash::class,
];

Publish the package specific assets and view using

php artisan vendor:publish

This will publish the flash view into resources/views/vendor/smodav/flash/ directory and also its accompanying css and javascript files into their respective resources/assets/ directory.

Usage

The package comes with a helper function flash() and its respective facade Flash. Within your controllers or closures, use either before a redirect:

public function delete()
{
    flash()->success('Users', 'Successfully banned user.');

    return redirect()->route('users.index');
}

// OR

public function delete()
{
    Flash::success('Users', 'Successfully banned user.');

    return redirect()->route('users.index');
}

If you would like the notification to persist till dismissed by the user, use the persist() method on the instance:

public function delete()
{
    Flash::success('Users', 'Successfully banned user.')->persist();

    return redirect()->route('users.index');
}

The package has allows you to send different types of flash alerts:

  • Flash::info('Title', 'Message')
  • Flash::success('Title', 'Message')
  • Flash::error('Title', 'Message')
  • Flash::warning('Title', 'Message')

All the above can be persisted using persist().

An additional notice() is included that provides a notice on the top right edge, however, the notice cannot be persisted:

  • Flash::notice('Message')
public function delete()
{
    Flash::notice('Successfully banned user.');

    return redirect()->route('users.index');
}

For a basic flash instance of type info, just use the flash helper function: flash(Title, Message)

When using Laravel, this package creates flash session keys:

Alerts

  • sf_title containing the title of the flash message.
  • sf_message containing the actual flash message.
  • sf_level containing the level of flash message.
  • sf_persist only present when persist is used.

Notices

  • sf_notice_message containing the flash notice message.

Within your views, include the flash view and the corresponding css and javascript files. You may modify the flash view and add more functionality to the flash instances by passing the properties described in Sweet Alert to the sflash instance:

sflash({
    title: "{{ session('sf_title') }}",
    text: "{{ session('sf_message') }}",
    type: "{{ session('sf_level') }}",
    allowOutsideClick: true,
    confirmButtonText: "Okay Man",
    showConfirmButton: true
});