update email with unique validation in laravel

Created 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

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.