Need help with setting up a nested hierarchy taxonomy

Published 1 week ago by madsynn

I am trying to use googles taxonomy but not sure how or the easiest way to do this.

do i need to put each parent in a parent table? then each sub under that and then the next one after that?

And once its in my tables how would i reference it when doing queries to i later.

Need help any help would be great

Trying to make this work for products and them reference it when its queried.

Animals & Pet Supplies
Animals & Pet Supplies,Live Animals
Animals & Pet Supplies,Pet Supplies
Animals & Pet Supplies,Pet Supplies,Bird Supplies
Animals & Pet Supplies,Pet Supplies,Bird Supplies,Bird Cage Accessories
Animals & Pet Supplies,Pet Supplies,Bird Supplies,Bird Cage Accessories,Bird Cage Bird Baths
D9705996
D9705996
1 week ago (127,290 XP)

What your are describing is a nested set. There are laravel specific packages that can help you get up &running e.g.

https://github.com/lazychaser/laravel-nestedset

From the documentation you can do something like

$node = Category::create(['name' => 'Animals and Pet Supplies']);
$node->children()->create(['name' => 'live animals']);
$node->children()->create(['name' => 'pet supplies']);
...
$tree = Category::get()->toTree();

If not used the package so YMMV

Please sign in or create an account to participate in this conversation.