Laravel Classroom image

Prashant  Nigam / Student / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9|Last
Lessons:-Handling Input

8.2 Errors
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.
1 <?php
2
3 $age_errors = $v->errors->get('age');
Now we have an array containing all of the errors associated with the age field..
1 <?php
2
3 array(
4 'The age must be at least 16.'
5 )
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 ) ?>
Neat!
You can also use has() to check to see if an error exists, and all() to retrieve all errors as an
array.

 

 
 
 

Prashant  Nigam

Skills    Laravel

Qualifications :-
Location :-,,,
Description:-
Explore
 

  Students (0)