So user needs to update products and users products must have unique names and I don't want the user to receive the error message Product with same name already exists
How do tweak the Laravel's unique validator to do this
$sql = "SELECT `id` FROM `products` WHERE `name` = '$value' AND user_id != '$user_id' AND id != '$id' ";
This will ensure that if user decides to leave product name unchanged, there will not be any error message for product name with same already exists as long as it belongs to the same user and the product id remains same
I have tried this in FormRequest rules()
$id = $this->route('id');
$user_id = $this->user()->id;
return [
'name'=>"unique:product,name,user_id,$user_id,id,$id"
];
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire