@whoisthisstud what if you try it is unique excluding the current row:
'zip_code' => 'integer|unique:cities,id,'.$this->id
I guess you have id in your cities table.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am attempting to use the same request validation for updating as I use for creating a record, but I continue to get an error when updating that the unique field isn't unique.
StoreCityRequest
public function rules()
{
return [
'name' => 'required|max:255',
'zip_code' => 'integer|unique:cities,zip_code,'.$this->zip_code
];
}
I have tried $this->id, $request->id, $this->zip_code, $request->zip_code... and they all result in failing validation with a "This zip_code has already been taken".
Where am I going wrong?
TIA.
@whoisthisstud before returning the rules array dump the request('city') using dd(request('city')) see what it spits out, it seems like is an instance of the city model.
or use $this->city->id.
Please or to participate in this conversation.