Laravel Classroom image

Yasar  Khan / 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.5 Custom Validation Rules
The validator allows you add extra rules to suit the needs of your application, let’s jump right in
and take a look at how we register a new validation rule.
1 <?php
3 Validator::register('superdooper', function($attribute, $value, $parameters\
4 ){
5 return $value == 'superdooper';
6 });
Our newly created validation rule superdooper will ensure that our value matches the string
‘superdooper’. Your custom validations should return true on success, or false on failure.
The $attribute value will be the name of the field being validated, and $value will of course
contain the value.
The $parameters attribute contains an array of parameters that have been passed to the rule
after the colon, and separated by commas.
As you have created a new validator, there will be no error messages associated with it yet, we
will need to add one so that Laravel knows what to say when it fails. We can add an error
message in the same way as we have previously..
1 <?php
3 'superdooper' => 'The :attribute must be superdooper, ok trooper?!',
Once again you can pass the extra error message array as a third parameter to the Validator::
make() method, or simply add it to your application/language/en/validation.php file
for safe keeping.


Yasar  Khan

Skills    Laravel

Qualifications :-
Location :-Dehradun,Dehradun,Uttarakhand,India
Description:- Hi i am yasar working as web developer since last 3 years.

  Students (0)