dev-master
9999999-dev https://mauricioschmitz@bitbucket.org/mauricioschmitz/laravel-toastr.gitToastr - Flash Messages for Laravel 5
MIT
The Requires
- illuminate/support ~5.1
- php >=5.3.0
laravel 5 toastr alerts flash messages
Wallogit.com
2017 © Pedro Peláez
Toastr - Flash Messages for Laravel 5
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)
Use composer require command to install this package., (*2)
``` bash $ composer require mauricioschmitz/laravel-toastr, (*3)
#### Laravel version Compatibility Laravel | Package :---------|:---------- 5.0.x | 1.0.x 5.1.x | 1.0.x 5.2.x | 2.0.x 5.3.x | 2.0.x 5.4.x | 2.0.x #### Adding package to composer.json file manually Add package to your composer.json file:
"require": { "mauricioschmitz/laravel-toastr": "2.0.*" }, (*4)
Use [composer](http://getcomposer.org) update command to install this package. ``` bash $ composer update
Add the Toastr Service Provider to your config in config/app.php:, (*5)
'providers' => array(
Laraveltoastr\Toastr\Providers\ToastrServiceProvider::class,
),
and create an alias:, (*6)
'aliases' => [
'Laraveltoastr' => Laraveltoastr\Toastr\Facades\Toastr::class,
],
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)
If you use VUE.JS, you need install vue-toastr
npm install --save vue-toastr, (*9)
And then add to your app.js
import Toastr from 'vue-toastr'; require('vue-toastr/src/vue-toastr.less'); Vue.component('vue-toastr',Toastr);, (*10)
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')) @endif
And add javascript and css plugin, you can download on CodeSeven, (*11)
https://codeseven.github.io/toastr/
<link href="toastr.css" rel="stylesheet"/>
In your controllers/action before you perform a redirect:, (*12)
``` php public function login() { Toastr::success('Welcom back!')->push(); return Redirect::home(); }, (*13)
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:, (*14)
``` php, (*15)
// 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();, (*16)
// error alert with title Toastr::alert('danger',['Some title','Error - generated by alert() method'])->push();, (*17)
// succes Toastr::success('This is success')->push();, (*18)
// success with title Toastr::success('Excelent','This is success')->push();, (*19)
// info Toastr::info('That is just short info')->push();, (*20)
// warning Toastr::warning('Thats a warning!')->push();, (*21)
// error Toastr::danger('We got an error!')->push();, (*22)
// 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();, (*23)
```, (*24)
Toastr - Flash Messages for Laravel 5
MIT
laravel 5 toastr alerts flash messages