Answer the question
In order to leave comments, you need to log in
How to validate for uniqueness of 2 columns?
There is such code in migration
$table->unique([ "parent_id", "slug" ], "unique_slug");
"slug" => "required|unique:categories,slug,NULL,id,parent_id,$parentId"
[
"slug" => "my_slug",
"parent_id" => 1
]
[
"slug" => "my_slug",
"parent_id" => null
]
Answer the question
In order to leave comments, you need to log in
Judging by this question , uniqueness on two columns will not work in mysql if one of them is null. I did not dig further in this direction and did so. Only the slug field is unique and is stored as parent_parent_..._parent_slug/.../parent_slug/slug. Yes, when you need to update the slug, you need to get all the descendants and update this field from them too, but when you need to read the record to find out the full slug, you don’t need to get all the ancestors
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question