skip to Main Content

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


  1. Chosen as BEST ANSWER

    'mobile'=>[ 'required', Rule::unique('operators', 'mobile')->ignore($this->operator)]

    it works


  2. 'mobile' => ['required', Rule::unique('operators')->ignore($operator->id)]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search