2017 © Pedro Peláez
 

library flash

Easy flash notifications for laravel 5

image

znck/flash

Easy flash notifications for laravel 5

  • Tuesday, January 12, 2016
  • by znck
  • Repository
  • 1 Watchers
  • 0 Stars
  • 159 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 11 Versions
  • 1 % Grown

The README.md

Flash

Easy flash notifications for Laravel 5, (*1)

Installation

First, pull in the package through Composer., (*2)

"require": {
    "znck/flash": "~1.2"
}

And then, if using Laravel 5, include the service provider within app/config/app.php., (*3)

'providers' => [
    'Znck\Flash\FlashServiceProvider'
];

And, for convenience, add a facade alias to this same file at the bottom:, (*4)

'aliases' => [
    'Flash' => 'Znck\Flash\Flash'
];

Usage

Within your controllers, before you perform a redirect..., (*5)

public function store()
{
    Flash::message('Welcome Aboard!');

    return Redirect::home();
}

You may also do:, (*6)

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

This will set a few keys in the session:, (*7)

  • 'znck.flash.notifications' - Session key for flash notification's message bag

Each message will have these keys:, (*8)

  • 'message' - The message you're flashing
  • 'level' - A string that represents the HTML class for displaying the message
  • 'sort' - Level weight used to sort the messages.

Alternatively, again, you may reference the flash() helper function, instead of the facade. Here's an example:, (*9)

/**
 * Destroy the user's session (logout).
 *
 * @return Response
 */
public function destroy()
{
    Auth::logout();

    flash()->success('You have been logged out.');

    return home();
}

Or, for a general information flash, just do: flash('Some message');., (*10)

With this message flashed to the session, you may now display it in your view(s). Maybe something like:, (*11)

@foreach(flash()->get() as $notification)


{!! $notification['message'] !!}
@endforeach

You may also do:, (*12)

  • Flash::get()
  • flash()->get()

Flash::get() or flash()->get() function can take an optional variable to filter the result. Eg:, (*13)

php
Flash::get('*'); // To get all messages.
Flash::get('info'); // To get only messages with info level.
Flash::get('info|warning'); // To get messages with info or warning level

You can publish the config file to add custom message levels and reorder messages., (*14)

// Default messagle levels and their sort order
[
    'classes' => [
        'error'   => 'danger',
        'warning' => 'warning',
        'success' => 'success',
        'info'    => 'info',
    ],

    'levels'  => [
        'error'   => 400,
        'warning' => 300,
        'success' => 200,
        'info'    => 100,
    ]
];

Note that this package is optimized for use with Twitter Bootstrap., (*15)

Because flash messages and overlays are so common, if you want, you may use (or modify) the views that are included with this package. Simply append to your layout view:, (*16)

@include('znck::flash.notifications')

Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
</head>
<body>



@include('flash::message')

Welcome to my website..., (*17)

</body> </html>

If you need to modify the flash message partials, you can run:, (*18)

php artisan vendor:publish

The two package views will now be located in the `app/views/packages/laracasts/flash/' directory., (*19)

Flash::message('Welcome aboard!');

return Redirect::home();

https://dl.dropboxusercontent.com/u/774859/GitHub-Repos/flash/message.png, (*20)

Flash::error('Sorry! Please try again.');

return Redirect::home();

https://dl.dropboxusercontent.com/u/774859/GitHub-Repos/flash/error.png, (*21)

Flash::overlay('You are now a Laracasts member!');

return Redirect::home();

https://dl.dropboxusercontent.com/u/774859/GitHub-Repos/flash/overlay.png, (*22)

The Versions

12/01 2016
12/01 2016
11/08 2015
08/05 2015
08/05 2015
08/04 2015
08/04 2015
02/04 2015

v1.0.1

1.0.1.0 https://github.com/znck/flash

Easy flash notifications for laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

02/04 2015

v1.0.0

1.0.0.0 https://github.com/znck/flash

Easy flash notifications for laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires