Skip to content

Commit 4714d45

Browse files
authored
Merge pull request #91 from inerba/inerba-documentation-patch-1
Improve Advanced usage documentation
2 parents 6e3cb79 + 2af9d54 commit 4714d45

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,27 @@ class CategoryTree extends TreePage
397397
}
398398
```
399399

400+
### Customizing Data Display in Tree Widgets
401+
402+
For advanced use cases, you may want to limit or customize the data displayed in your tree widget: for example, showing only items matching specific criteria or related to a parent resource.
403+
404+
You can achieve this by overriding the getTreeQuery method in your widget, allowing full control over the Eloquent query used to fetch records.
405+
406+
```php
407+
use App\Models\Menuitem;
408+
use Illuminate\Database\Eloquent\Builder;
409+
class MenuItemsWidget extends Tree
410+
{
411+
// Accessing the current record in the widget
412+
public ?Model $record = null;
413+
414+
protected function getTreeQuery(): Builder
415+
{
416+
return MenuItem::query()
417+
->where('menu_id', $this->record?->id); // Filter by the current menu ID
418+
}
419+
```
420+
400421
### Custom Column Names
401422

402423
Override default column names if your table structure differs:

0 commit comments

Comments
 (0)