Closed GoodJob closed 7 months ago
I'm unsure how this could be considered a bug in the plugin. @GoodJob
Yes, it is not directly.
But the problem with filter. If I have Main Category and the Additional Categories. I can do only one filter for categories. So if I want Main Category to be included to Filter as well as Additional Categories - I have to save it to Additional Categories table!
Can you show me an example video/snapshot? @GoodJob
Or you can tell me or you have tested items with double selection - Main Category and Multiple Categories and how did you solved out with filter?
I'm not sure about the issue at hand, which is why I'm requesting a video or snapshot. If the problem lies in the inability to select multiple categories, that should be possible as long as your relationship isn't a BelongsTo
.
this is two fields I'm using: Main Category Additional Categories
And filter code only takes Additional Categories:
Filter::make('tree')
->form([
SelectTree::make('categories')
->relationship('categories', 'name', 'parent_id')
->independent(false)
->enableBranchNode(),
])
->query(function (Builder $query, array $data) {
return $query->when($data['categories'], function ($query, $categories) {
return $query->whereHas('categories', fn($query) => $query->whereIn('categories.id', $categories));
});
})
->indicateUsing(function (array $data): ?string {
if (! $data['categories']) {
return null;
}
return __('Categories') . ': ' . implode(', ', Category::whereIn('id', $data['categories'])->get()->pluck('name')->toArray());
}),
If the first field corresponds to another table, then it won't work. The SelectTree only operates with one table at a time.
What happened?
If there are no additional record of category_id in
category_product
table - filament-select-tree doesn't select that records using filter. Main Category has to be added also on belongsToMany table, for provided Filter exampleHow to reproduce the bug
I'm saving in:
record is saved on
category_product
, but then somehow deleted by Filament pipeline I asume so.Package Version
2.0
PHP Version
8.2
Laravel Version
10
Which operating systems does with happen with?
No response
Notes
No response