I think you need sometimes rule instead of required. It applies only if the field under the rule is present in validated data.
https://laravel.com/docs/13.x/validation#validating-when-present
Hello to everyone. In my customers table the user can define a customer code which must be unique. In the StoreCustomer request I have set the following rule:
'custcode' => 'required|max:5|min:5|unique:customers,custcode',
In case the user wants to correct the customer code, in the UpdateCustomer request I have the same rule:
'custcode' => 'required|max:5|min:5|unique:customers,custcode',
The problem arises when the user wants to update i.e. only a customer's address. Then I have the error message "this customer code already exists in this table". Given that the change of a wrong customer code must always be allowed, how can I overcome this problem? The customer code must be unique ok sure. But if I want to change a wrong accidentally given code, what is the correct way to do this? Also if the useer has the purpose to change something else, he facces this message for the customer code. Thank you Panagiotis
Please or to participate in this conversation.