@@ -275,6 +275,66 @@ If you need to append an item to the tree menu, use the `append` method. This me
275275 ])
276276```
277277
278+ If you need full control over the tree structure, you can use ` getTreeUsing ` to provide a custom tree array, or a closure that resolves to an array.
279+
280+ Using an array:
281+
282+ ``` php
283+ SelectTree::make('categories')
284+ ->getTreeUsing([
285+ [
286+ 'name' => 'Parent Category',
287+ 'value' => '1',
288+ 'children' => [
289+ [
290+ 'name' => 'Child Category',
291+ 'value' => '2',
292+ 'children' => [],
293+ ],
294+ ],
295+ ],
296+ [
297+ 'name' => 'Another Category',
298+ 'value' => '3',
299+ 'children' => [],
300+ ],
301+ ])
302+ ```
303+
304+ Using a closure for dynamic data:
305+
306+ ``` php
307+ SelectTree::make('categories')
308+ ->getTreeUsing(function () {
309+ return Category::query()
310+ ->get()
311+ ->map(fn ($category) => [
312+ 'name' => $category->name,
313+ 'value' => $category->id,
314+ 'children' => $category->children->map(fn ($child) => [
315+ 'name' => $child->name,
316+ 'value' => $child->id,
317+ 'children' => [],
318+ ])->toArray(),
319+ ])
320+ ->toArray();
321+ })
322+ ```
323+
324+ The tree structure should follow this format:
325+
326+ ``` php
327+ [
328+ [
329+ 'name' => 'Display Name',
330+ 'value' => 'option_value',
331+ 'disabled' => false, // optional
332+ 'hidden' => false, // optional
333+ 'children' => [], // optional
334+ ],
335+ ]
336+ ```
337+
278338## Filters
279339
280340Use the tree in your table filters. Here's an example to show you how.
0 commit comments