Laravel Classroom image

Anil  Bist / Professional / 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.

 

 
 
 
image
Anil  Bist

Skills    Laravel

Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,
Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-

I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore

 

  Students (0)