The following validation works when creating a new record, but when updating a record, partner_code
and seedgens_code
get stuck in unique
validation. How can I allow a record to be updated with the same value if it hasn't changed, but still verify uniqueness when the value changes?
$this->validate( [ 'partner_code' => 'required|unique:varieties', 'seedgens_code' => 'required|unique:varieties', ], [ 'partner_code.required' => 'Please add a partner code.', 'partner_code.unique' => 'Partner code must be unique.', 'seedgens_code.required' => 'Please add a unique partner code.', 'seedgens_code.unique' => 'SeedGens code must be unique.', ], );
My adding the rule to (1) does not work I added the rule to (2) and it's working! ! !
or
Where
$id
is the ID you want to ignore.https://laravel.com/docs/9.x/validation #RULE UNIQUE