dev-master
9999999-devFlash Messages made easy. Based on laracasts/flash
MIT
The Requires
- php >=5.4.0
- illuminate/support ~5.0
The Development Requires
by Matheus
Flash Messages made easy. Based on laracasts/flash
First, pull in the package through Composer., (*1)
Run composer require mtxr/laravel-flash-message
, (*2)
And then, if using Laravel 5, include the service provider within config/app.php
., (*3)
'providers' => [ FlashMessage\FlashServiceProvider::class, ];
Within your controllers, before you perform a redirect..., (*4)
public function store() { flash('Welcome Aboard!'); return home(); }
You may also do:, (*5)
flash('Message', 'info')
flash('Message', 'success')
flash('Message', 'danger')
flash('Message', 'warning')
flash('Message')->important()
Adding Icons:
- flash('Message')->icon('fa fa-exclamation-circle')
, (*6)
Deleting last message:
- flash()->delete()
, (*7)
Clearing message queue:
- flash()->clear()
, (*8)
If you need, you can flash two messages in the same request:, (*9)
public function welcome() { flash('Welcome Aboard!', 'success'); flash('Request Failed!', 'error'); return home(); }
Behind the scenes, this will set a few keys in the session:, (*10)
With this message flashed to the session, you may now display it in your view(s). Maybe something like:, (*11)
@if (session()->has('flash_notification.messages')) @foreach(session('flash_notification.messages') as $messageData)@if(!$messageData['important']) @endif {!! trans($messageData['message']) !!}@endforeach @endif
Note that this package is optimized for use with Twitter Bootstrap., (*12)
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:, (*13)
@include('flash::message')
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> </head> <body>@include('flash::message')</body> </html>Welcome to my website..., (*14)
If you need to modify the flash message partials, you can run:, (*15)
php artisan vendor:publish
The package view will now be located in the app/views/packages/mtxr/laravel-flash-message/
directory., (*16)
A common desire is to display a flash message for a few seconds, and then hide it. To handle this, write a simple bit of JavaScript. For example, using jQuery, you might add the following snippet just before the closing </body>
tag., (*17)
<script type="text/javascript"> $('.flash-message.alert').not('.alert-important').delay(5000).slideUp(350); </script>
This will find any alerts - excluding the important ones, which should remain until manually closed by the user - wait three seconds, and then fade them out., (*18)
Flash Messages made easy. Based on laracasts/flash
MIT