update email with unique validation in laravel

You can update the email with unique validation on update user record with ignoring the current user email id.

Answers 1
  • Update email with unique validation ignoring current email on update record in laravel

    --PATH app\Http\Controllers\<YourController>.php
        'email' => ['required', 'string', 'email', 'max:255','unique:users,email,'.$userId]

    This code snippet will update the user email if email already does not exist in the table ignoring the current user email in the table. Variable $userId is the user which will be ignored while executing the unique validation in laravel which is the current user ID.

  • Back to code snippet queries related laravel