This is a laravel package for displaying flash notifications that extends Sweet Alert and provides an extra custom notice notification on the top left.
Clone or download
Latest commit b1e6c9a Jul 26, 2016
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
resources fixing notice Jul 26, 2016
src/Flash little housekeeping Jun 15, 2016
tests broaden compatibility Jun 15, 2016
.gitignore fixing gitignore Jun 15, 2016
.travis.yml broaden compatibility Jun 15, 2016
LICENSE patching up Jun 15, 2016
README.md publishing assets and readme Jun 16, 2016
composer.json broaden compatibility Jun 15, 2016
phpunit.xml performing tests Jun 15, 2016

README.md

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