andersao/laravel-validator

how Can I user custom roles

abdullah-abunada opened this issue · 3 comments

Hi,

how we can use custom roles inside validator like this

'email' => [
        'required',
        Rule::exists('staff')->where(function ($query) {
            $query->where('account_id', 1);
        }),
    ],

same question

@gebaiwan @abdullah-abunada I guess you can do something like this:

class ExampleValidator extends LaravelValidator
{
    public function __construct(Factory $validator)
    {
        parent::__construct($validator);

        $this->rules = [
            self::RULE_CREATE => [ ],
            self::RULE_UPDATE => [
                'status'    => ['integer', new ExampleStatusUpdateRule()]
            ],
        ];
    }
}

This works for me.

@gebaiwan @abdullah-abunada I guess you can do something like this:

class ExampleValidator extends LaravelValidator
{
    public function __construct(Factory $validator)
    {
        parent::__construct($validator);

        $this->rules = [
            self::RULE_CREATE => [ ],
            self::RULE_UPDATE => [
                'status'    => ['integer', new ExampleStatusUpdateRule()]
            ],
        ];
    }
}

This works for me.

thanks for your help.
and i what skip this validator,just use laravel formrequest, what should I do