I’m using Laravel for my web application and have a ‘mobile’ field that I want to update. I’m using the following validation rule:
'mobile' => ['required', Rule::unique('operators')->ignore(/* unsure what to put here */)]
I want to update the mobile number, but I need to ignore the unique validation for the ‘mobile’ field if the requested mobile number is the same as the one currently in the database for the authenticated user. In other words, users should be allowed to keep their current mobile number without triggering the unique validation error.
Could someone please guide me on how to achieve this in Laravel? Any help or code examples would be highly appreciated.
Thank you!
2
Answers
'mobile'=>[ 'required', Rule::unique('operators', 'mobile')->ignore($this->operator)]
it works