If your validation fails, which it will because our user is under 16 (sorry for slaying your
sparklepony), you will want to find out what went wrong. The validator provides an errors
Messages object which allows us to easily find the information we need.
The errors object has similar methods to the Input class, so I will not need to go over them all.
Let’s retrieve an array of errors for a specific field.
3 $age_errors = $v->errors->get('age');
Now we have an array containing all of the errors associated with the age field..
4 'The age must be at least 16.'
Most of the time I find myself using the first() method in my views, which returns the first
array item if it exists, or null if it doesn’t. For example..
1 <?php echo Form::label('username', 'Username') ?>
2 <?php echo $errors->first('username') ?>
3 <?php echo Form::text('username') ?>
Now our validation errors will appear for this field if any are present. You can also pass a second
parameter to the first() method to format the output..
1 <?php echo $errors->first('username', '<span class="error">:message</span>'\
2 ) ?>
You can also use has() to check to see if an error exists, and all() to retrieve all errors as an