You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To use Filament Tree, follow these table structure conventions:
76
66
77
67
> **Tip: The `parent_id` field must always default to -1!!!**
78
68
79
69
```
80
70
Schema::create('product_categories', function (Blueprint $table) {
81
-
$table->id();
82
-
$table->integer('parent_id')->default(-1);
83
-
$table->integer('order')->default(0)->index();
84
-
$table->string('title');
85
-
$table->timestamps();
86
-
});
71
+
$table->id();
72
+
$table->integer('parent_id')->default(-1);
73
+
$table->integer('order')->default(0)->index();
74
+
$table->string('title');
75
+
$table->timestamps();
76
+
});
77
+
```
78
+
This plugin provides a convenient method called `treeColumns()` that you can use to add the required columns for the tree structure to your table more easily. Here's an example:
87
79
```
80
+
Schema::create('product_categories', function (Blueprint $table) {
81
+
$table->id();
82
+
$table->treeColumns();
83
+
$table->timestamps();
84
+
});
85
+
```
86
+
This will automatically add the required columns for the tree structure to your table.
87
+
88
88
89
89
The above table structure contains three required fields: `parent_id`, `order`, `title`, and other fields do not have any requirements.
90
90
@@ -157,15 +157,28 @@ class ProductCategory extends Model
157
157
158
158
```
159
159
160
-
### Create Tree Widget
160
+
### Widget
161
+
Filament provides a powerful feature that allows you to display widgets inside pages, below the header and above the footer. This can be useful for adding additional functionality to your resource pages.
162
+
163
+
To create a Tree Widget and apply it to a resource page, you can follow these steps:
164
+
165
+
#### 1. Creating a Filament Resource Page
166
+
To create a resources page, run the following command:
The `getTreeActions()` method defines the actions that are displayed for each record in the tree. For example:
276
+
```php
277
+
use Filament\Pages\Actions\Action;
278
+
279
+
protected function getTreeActions(): array
280
+
{
281
+
return [
282
+
Actions\ViewAction::make(),
283
+
Actions\EditAction::make(),
284
+
Actions\DeleteAction::make(),
285
+
];
286
+
}
287
+
288
+
```
289
+
290
+
Alternatively, you can use the `hasDeleteAction()`, `hasEditAction()`, and `hasViewAction()` methods to customize each action individually.
291
+
292
+
```php
293
+
protected function hasDeleteAction(): bool
294
+
{
295
+
return false;
296
+
}
297
+
298
+
protected function hasEditAction(): bool
299
+
{
300
+
return true;
301
+
}
302
+
303
+
protected function hasViewAction(): bool
304
+
{
305
+
return false;
306
+
}
307
+
```
308
+
#### Record ICON
309
+
To customize the prefix icon for each record in a tree page, you can use the `getTreeRecordIcon()` method in your tree page class. This method should return a string that represents the name of the icon you want to use for the record. For example:
310
+
311
+
```php
312
+
public function getTreeRecordIcon(?\Illuminate\Database\Eloquent\Model $record = null): ?string
This plugin enables you to create tree pages in the admin panel. To create a tree page for a model, use the `make:filament-tree-page` command. For example, to create a tree page for the ProductCategory model, you can run:
323
+
#### Create a Page
324
+
> **Tip: Note that you should make sure the model contains the required columns or already uses the `ModelTree` trait**
Once you've created the tree page, you can customize the available actions, widgets, and icon for each record. You can use the same methods as for resource pages. See the [Resource Page](#resources) for more information on how to customize actions, widgets, and icons.
0 commit comments