SmoDav / flash by SmoDav

Flash messaging package for use with laravel
256
3
2
Package Data
Maintainer Username: SmoDav
Maintainer Contact: smodavprivate@gmail.com (SmoDav)
Package Create Date: 2016-06-15
Package Last Update: 2016-07-26
Home Page:
Language: CSS
License: MIT
Last Refreshed: 2024-04-22 03:01:53
Package Statistics
Total Downloads: 256
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 3
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Flash Notifier

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
});