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.4 Custom Error Messages
I find the default error messages quite descriptive, but your clients might have their own ideas.
Let’s see how we can customize our error messages to suit our needs.
You can edit the validation error messages directly by modifying the file application/language/
en/validation.php…
1 ...
2 "after" => "The :attribute must be a date after :date.",
3 "alpha" => "The :attribute may only contain letters.",
4 "alpha_dash" => "The :attribute may only contain letters, numbers, and \
5 dashes.",
6 ...
Laravel replaces the :attribute marker with the name of the field. Other markers also exist
within the rules, and their purpose is quite self explanatory.
If you would rather change the messages for a single form, rather than edit them globally, you
can pass a third array of messages to the Validator::make() method.
1 <?php
2
3 $messages = array(
4 'same' => 'The :attribute and :other must match, fool!',
5 'size' => 'The :attribute must be exactly :size , like duh!'
6 );
7
8 $v = Validator::make($input, $rules, $messages);
Great now we have custom messages! We can even specify error messages for individual fields
by setting the message key to field_rule, for example..1 <?php
2
3 $messages = array(
4 'age_required' => 'You need to have had at least one birthday!'
5 );

 
 
 

Prashant  Nigam

Skills    Laravel

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

  Students (0)