Try running dd on the id to check if its correct
dd($this->id);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, I'm asking for a piece of advice and help on how can I add unique rules on name and code when a user tries to store and update product details
Here is the code from the ProductStoreRequest Form request class code
return [
'name' => ['required', Rule::unique('products')->ignore($this->id)],
'code' => ['required', Rule::unique('products')->ignore($this->id)],
'qty' => ['numeric'],
'product_tag' => ['required']
];
when the user tries to store it works perfectly.
if the user tries to update the same product then it should ignore the current id but it gives a validation message for unique value
Here is the API response on update
"errors": [
{
"name": "The name has already been taken."
},
{
"code": "The code has already been taken."
}
]
Is something am I missing, please help me with this! Many thanks!
Please or to participate in this conversation.