Creating a custom error message
Laravel has built-in error messages if a validation fails, but we may want to customize those messages to make our application unique. This recipe shows a few different ways to create custom error messages.
Getting ready
For this recipe, we just need a standard installation of Laravel.
How to do it...
To complete this recipe, follow these steps:
Create a route in
routes.php
to hold the form:Route::get('myform', function() { return View::make('myform'); });
Create a view named
myform.php
and add a form:<h1>User Info</h1> <?php $messages = $errors->all ('<p style="color:red">:message</p>') ?> <?php foreach ($messages as $msg) { echo $msg; } ?> <?= Form::open() ?> <?= Form::label('email', 'Email') ?> <?= Form::text('email', Input::old('email')) ?> <br> <?= Form::label('username', 'Username') ?> <?= Form::text('username', Input::old('username')) ?> <br> <?= Form::label...