CodeWithDennis / filament-select-tree

The multi-level select field lets you pick one or multiple options from a list that is neatly organized into different levels.
MIT License
225 stars 33 forks source link

[How to] Use SelectTree from one model in another model #58

Closed jlpellicer closed 10 months ago

jlpellicer commented 10 months ago

What happened?

Sorry, this is not a bug, but I couldn't find another way to ask this question. I'm new to Filament in general.

I have my ProductCategories working fine with the SelectTree. Now I have a Product model which has one of these ProductCategories and I want to add the SelectTree as a Table Filter and the new product form, but I can't get around how to.

As you would expect, my Products have a product_category_id and a belongsTo relationship to ProductCategories and a simple ->relationship('product_categories', 'title', 'id')  in a Select works just fine, but you can imagine that all Product Categories show up, all levels, no tree.

How to reproduce the bug

So, I don't know, maybe it can't be used like this? Has anyone used this plugin in this manner? Thanks in advance.

Package Version

3.1

PHP Version

8.2.13

Laravel Version

10.10

Which operating systems does with happen with?

macOS

Notes

No response

CodeWithDennis commented 10 months ago

The select tree works recursively only on its own model.

Category.php

id: 1
name: Test Category
category_id: null

id: 2
name: Test Sub Category
category_id: 1
jlpellicer commented 10 months ago

I see, thank you.

johncarter- commented 8 months ago

Did you manage to work around this requirement @jlpellicer ? I have the same issue, where I need to have separate models nested.

jlpellicer commented 8 months ago

I did @johncarter- but not with this plugin, I created a widget and filters to search for products

johncarter- commented 8 months ago

Thanks @jlpellicer, interesting approach, don't think that's going to work for me here. Thanks for coming back to me though 👍🏻