Laravel 9 Unique Validation on Update Example Tutorial

Throughout laravel 9 unique validation on update we are going to share laravel unique validation with condition where clause example. This example explain laravel validation unique ignore id or email.

You can use how to add unique validation on update in laravel 6, laravel 7, laravel 8 and laravel 9 application. Sometime we need to add unique validation on update for email, username etc. at that time if you check unique email or username then you have to write database query manually and do it using if condition.

Example 1: Using controller Update

public function update(Request $request, User $user)
{
  $request->validate([
      'email'  => 'required|unique:users,email,' . $user->id . ',id,project_id,' . $user->project_id,
  ]);
}

Example 2: Using Form Request


public function rules()
{
  return [
      'email'  => 'required|unique:users,email,' . $this->id . ',id,project_id,' . $this->project_id,
  ];
}

Learn Also: Laravel Unique Email Validation on Update Example

I hope Laravel Unique Validation with where query work for you. For more updates feel free to follow us on social networks.

2 thoughts on “Laravel 9 Unique Validation on Update Example Tutorial”

Leave a Comment