laravel unique except code example

Example 1: laravel unique validation

unique:table,column,except,idColumn

############## Example : ################

############### For Updating  
//rules
'email' => 'unique:users,email_address,' . $userId,

############### For Creating 
//rules
'email' => 'unique:users,email_address',

Example 2: validate field for existing client laravel

unique:users,username,id,1 // table, field, idcolumn, value to ignore

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),
            ]
        ];
    }

Tags:

Php Example