update email with unique validation in laravel

Updated at 20-Jul-2021, By samar

update email with unique validation in laravel

In this article, we will see how to solve "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.
  • Update email with unique validation ignoring current email on update record in laravel

    --PATH app\Http\Controllers\<YourController>.php
    $request->validate([
        '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