Reputation: 1005
Duplicates:
Laravel 8 Unique form validation ignore
following this doc
This is my request validation:
public function rules()
{
return [
'LFNumber' => ['required', 'integer', Rule::unique('lost_and_found', 'id')->ignore($this->id, 'id')],
];
}
I'm trying to edit
some fields of the form but I either get LFNumber already exist
or SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '1' for key 'LFNumber'
I tried Rule::unique('lost_and_found', 'LFNumber')->ignore($this->id, 'id')
to select the LFNumber
column and ignore the id. But still he same errors.
Upvotes: 0
Views: 96
Reputation: 177
If the unique column is LFNumber
then you don't need to provide it:
'LFNumber' => ['required', 'integer', Rule::unique('lost_and_found')->ignore($this->id)],
This will check lost_and_found.LFNumber
column while ignoring row with Primary Key matching $this->id
(assuming this value is really the id on that column)
Upvotes: 1