I stopped writing this myself for laravel in favor of the Laracasts package , which handles all this for you. It is very easy to use and keeps your code clean. There is even a laracast that describes how to use it. All you need to do:
Pull the bag through the composer.
"require": { "laracasts/flash": "~1.0" }
Enable the service provider in app / config / app.php.
'providers' => [ 'Laracasts\Flash\FlashServiceProvider' ];
Add the facade alias to the same file below:
'aliases' => [ 'Flash' => 'Laracasts\Flash\Flash' ];
Pull the HTML into the view:
@include('flash::message')
Next to the message is a close button. It depends on jQuery, so make sure it is added before your boot file.
additional changes:
If you are not using bootstrap or want to skip enabling flash messages and write the code yourself:
@if (Session::has('flash_notification.message')) <div class="{{ Session::get('flash_notification.level') }}"> {{ Session::get('flash_notification.message') }} </div> @endif
If you want to view the HTML code typed by @include('flash::message') , you can find it in vendor/laracasts/flash/src/views/message.blade.php .
If you need to change partial actions:
php artisan view:publish laracasts/flash
The views of the two packages will now be located in the `app / views / packages / laracasts / flash / 'directory.
DutGRIFF Dec 10 '14 at 16:21 2014-12-10 16:21
source share