Laravel Message Binder
A little hack for Illuminate View to access flash messages easily., (*1)
You can use the withMessages method like a laravel builtin method withErrors in a general purpose., (*2)
Route::get('register', function()
{
return View::make('user.register');
});
Route::post('register', function()
{
$rules = array(...);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails())
{
return Redirect::to('register')->withErrors($validator);
}
// You can use the `withMessages` method like a laravel builtin method `withErrors` in a general purpose.
return Redirect::to('register')->withMessages(array('default' => 'Success!');
});
After redirection, you may utilize the automatically bound $messages variable in your view:, (*3)
<?php echo $messages->first('default'); ?>
see also laravel docs#validation, (*4)
Installation
Add dependency in composer.json, (*5)
"require": {
"kohkimakimoto/laravel-message-binder": "0.*"
}
Run composer update command., (*6)
$ composer update
Add MessageBinderServiceProvider to providers array in app/config/app.php, (*7)
'providers' => array(
...
'Kohkimakimoto\MessageBinder\MessageBinderServiceProvider',
),
LICENSE
The MIT License, (*8)
Author
Kohki Makimoto kohki.makimoto@gmail.com, (*9)