laravel unique except code example
Example 1: laravel unique validation
unique:table,column,except,idColumn
'email' => 'unique:users,email_address,' . $userId,
'email' => 'unique:users,email_address',
Example 2: validate field for existing client laravel
unique:users,username,id,1
Example 3: laravel unique except, some operation on query
public function rules()
{
return [
'name' => [
'required',
'email',
Rule::unique('users', 'email')
->where(static function ($query) {
return $query->whereNull('deleted_at');
})
->ignore($this->user),
]
];
}