Simple flash messagges system to use with Laravel 5 Framework.
By default it relies on twitter bootstrap "alert" component.
You can display multiple flash messages in different types (success, info, warning, danger)
at once and to each message you can asign some custom params that will allow you for example
mark some of them as important etc., (*1)
First of all you need to add some code to your view scripts. In most cases it will be layout file
(or other place where you want to flash message be displayed).
You can use default view script distrubuted within this package by adding following code into
your view file:, (*7)
``` php
@include('toastr::alerts'), (*8)
or to gain more controll of the look and feel of your flash messages you can start with using following template
(just copy and paste it into a place where your application allerts should be displayed):
``` php
@if(Session::has('toastr.alerts'))
@foreach(Session::get('toastr.alerts') as $alert)
@if( ! empty($alert['title']))
{{ $alert['title'] }}
@endif
{{ $alert['message'] }}
@if(array_get($alert,'params.important')) (This alert is marked as important) @endif
@endforeach
@endif
In your controllers/action before you perform a redirect:, (*9)
``` php
public function login()
{
Toastr::success('Welcom back!')->push();
return Redirect::home();
}, (*10)
you can push more than one alert at once:
``` php
public function login()
{
Toastr::success('Welcom back!')->push();
Toastr::warning('You don\'t look too good today!')->push();
return Redirect::home();
}
Other usage examples:, (*11)
``` php, (*12)
// using alert() method - first param is an alert type socond one is a message:
Toastr::alert('danger','Error - generated by alert() method')->push();
Toastr::alert('danger','Error - generated by alert() method')->push();
Toastr::alert('info','Info - generated by alert() method')->push();
Toastr::alert('warning','Warning - generated by alert() method')->push();
Toastr::alert('success','Success - generated by alert() method')->push();, (*13)
// error alert with title
Toastr::alert('danger',['Some title','Error - generated by alert() method'])->push();, (*14)
// succes
Toastr::success('This is success')->push();, (*15)
// success with title
Toastr::success('Excelent','This is success')->push();, (*16)
// info
Toastr::info('That is just short info')->push();, (*17)
// warning
Toastr::warning('Thats a warning!')->push();, (*18)
// error
Toastr::danger('We got an error!')->push();, (*19)
// adding additional params to each alert (with() method allows you to pass some custom params that can be used later in a view script)
Toastr::danger('We got an error! And its marked as important')->with(['important' => true])->push();
Toastr::danger('We got an error!', 'But its not that important')->with(['important' => false])->push();, (*20)