Pepijnhockers
1 week ago

Required_if or exclude_if with integer as value

Posted 1 week ago by Pepijnhockers

I would like to add a validation rule to my project. Here is the situation:

I have created a form where the user either can choose between an existing customer from the existing database or directly create a new customer with the form.

In the validation, I would like to check if the user has chosen an existing customer or has filled in the form.

When the user has chosen a customer then the other attributes/validation rules need to be excluded from the validation.

So my question is it possible to use the exclude_if:anotherfield,value for an integer.


        return [
            'customer'                      => ['nullable', 'integer', ],    

            // Customer model specific attributes
            'initials'                      => ['exclude_if:customer, ', 'nullable', 'string', 'max:255'],
            'first_name'                    => ['required', 'string', 'max:255'],
            'last_name'                     => ['required', 'string', 'max:255'],
            'email'                         => ['required', 'string', 'email', 'max:255', 'unique:customers,email'],
            'gender'                        => ['required', 'boolean'],
            'phone_number'                  => ['nullable', 'string', 'max:255'],
            'birthday'                      => ['required', 'date'],
            'citizen_service_number'        => ['required', 'min:9', 'max:9', 'unique:customers,citizen_service_number'],
]

Please sign in or create an account to participate in this conversation.