I am creating a new required validation based on the required\_if which works fine. But I need to use this new required validation with the nullable validation in which my new required validation doesn't work. Here is my code which I use in the controller:

```
'number' => 'nullable|required_when_has_restriction:role,restriction_must_have_number|digits:11',

```

And this is the new validator:

```
class ValidatorServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Validator::extend('required_when_has_restriction', function ($attribute, $value, $parameters, $validator) {
            $other = Arr::get($validator->getData(), $parameters[0]);

            $role = Role::where('name', $other)->first();
            if($role->permissions()->where('name', $parameters[1])->exists()){
                return $validator->validateRequired($attribute, $value);
            }
            return true;
        });
    }

    public function register()
    {
        //
    }
}

```

I want that this validator still works when the field is null, because I need the nullable validation for the digits. Could someone explain how to solve this?