0

I am using confide for user authentication. I wanna use custom rules using laravel's Validator (for firstname and lastname) class as in

$validator = Validator::make($user, $this->rules[$ruleset]);

and check with $validator->passes(). How can I achieve this?

Bishal Paudel
  • 1,896
  • 2
  • 21
  • 28

1 Answers1

1

First create your custom validation class. Something like this:

class CustomValidator 
{
    /** 
     * @return bool 
     */
    public function validateFirstname($attribute, $value, $parameters) {
    {
        // Do here your Firstname validation 
        ... 
    }

    /** 
     * @return bool 
     */
    public function validateLastname($attribute, $value, $parameters) {
    {
        // Do here your Lastname validation 
        ... 
    }

}

Then register the new validation rules. For example at bootstrap/start.php file add:

Validator::extend('firstname', 'CustomValidator@validateFirstname');
Validator::extend('lastname', 'CustomValidator@validateLastname');

Then you can use the new rules firtsname and lastname in your models.

I hope it works fine for you.

fmgonzalez
  • 823
  • 1
  • 7
  • 17