Skip to content

Commit c04bef6

Browse files
committed
Add sample code
1 parent 0898d78 commit c04bef6

File tree

3 files changed

+123
-9
lines changed

3 files changed

+123
-9
lines changed

stubs/TreePage.stub

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,19 @@ use SolutionForest\FilamentTree\Support\Utils;
1212

1313
class {{ class }} extends BasePage
1414
{
15+
protected static string $model = {{ modelClass }}::class;
16+
1517
protected static ?string $navigationIcon = 'heroicon-o-document-text';
1618

17-
public static function getMaxDepth(): int
18-
{
19-
return 2;
20-
}
19+
protected static int $maxDepth = 2;
2120

22-
public function getModel(): string
21+
protected function getActions(): array
2322
{
24-
return {{ modelClass }}::class;
23+
return [
24+
$this->getCreateAction(),
25+
// SAMPLE CODE, CAN DELETE
26+
//\Filament\Pages\Actions\Action::make('sampleAction'),
27+
];
2528
}
2629

2730
protected function getFormSchema(): array
@@ -30,4 +33,35 @@ class {{ class }} extends BasePage
3033
//
3134
];
3235
}
36+
37+
protected function hasDeleteAction(): bool
38+
{
39+
return false;
40+
}
41+
42+
protected function hasEditAction(): bool
43+
{
44+
return true;
45+
}
46+
47+
protected function hasViewAction(): bool
48+
{
49+
return false;
50+
}
51+
52+
protected function getHeaderWidgets(): array
53+
{
54+
return [];
55+
}
56+
57+
protected function getFooterWidgets(): array
58+
{
59+
return [];
60+
}
61+
62+
// CUSTOMIZE ICON OF EACH RECORD, CAN DELETE
63+
// public function getTreeRecordIcon(?\Illuminate\Database\Eloquent\Model $record = null): ?string
64+
// {
65+
// return null;
66+
// }
3367
}

stubs/TreeResourcePage.stub

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,45 @@ class {{ class }} extends BasePage
1313
{
1414
protected static string $resource = {{ resourceClass }}::class;
1515

16+
protected static int $maxDepth = 2;
17+
1618
protected function getActions(): array
1719
{
1820
return [
1921
$this->getCreateAction(),
22+
// SAMPLE CODE, CAN DELETE
23+
//\Filament\Pages\Actions\Action::make('sampleAction'),
2024
];
2125
}
2226

23-
public static function getMaxDepth(): int
27+
protected function hasDeleteAction(): bool
28+
{
29+
return false;
30+
}
31+
32+
protected function hasEditAction(): bool
33+
{
34+
return true;
35+
}
36+
37+
protected function hasViewAction(): bool
2438
{
25-
return 2;
39+
return false;
2640
}
41+
42+
protected function getHeaderWidgets(): array
43+
{
44+
return [];
45+
}
46+
47+
protected function getFooterWidgets(): array
48+
{
49+
return [];
50+
}
51+
52+
// CUSTOMIZE ICON OF EACH RECORD, CAN DELETE
53+
// public function getTreeRecordIcon(?\Illuminate\Database\Eloquent\Model $record = null): ?string
54+
// {
55+
// return null;
56+
// }
2757
}

stubs/TreeWidget.stub

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
namespace {{ namespace }};
44

55
use App\Models\{{ model }};
6-
use App\Filament\Widgets;
6+
use Filament\Notifications\Notification;
7+
use SolutionForest\FilamentTree\Actions\Action;
8+
use SolutionForest\FilamentTree\Actions\ActionGroup;
9+
use SolutionForest\FilamentTree\Actions\DeleteAction;
10+
use SolutionForest\FilamentTree\Actions\EditAction;
11+
use SolutionForest\FilamentTree\Actions\ViewAction;
712
use SolutionForest\FilamentTree\Widgets\Tree as BaseWidget;
813

914
class {{ class }} extends BaseWidget
@@ -15,4 +20,49 @@ class {{ class }} extends BaseWidget
1520
protected ?string $treeTitle = '{{ class }}';
1621

1722
protected bool $enableTreeTitle = true;
23+
24+
protected function getFormSchema(): array
25+
{
26+
return [
27+
//
28+
];
29+
}
30+
31+
// CUSTOMIZE ICON OF EACH RECORD, CAN DELETE
32+
// public function getTreeRecordIcon(?\Illuminate\Database\Eloquent\Model $record = null): ?string
33+
// {
34+
// return null;
35+
// }
36+
37+
// CUSTOMIZE ACTION OF EACH RECORD, CAN DELETE
38+
// protected function getTreeActions(): array
39+
// {
40+
// return [
41+
// Action::make('helloWorld')
42+
// ->action(function () {
43+
// Notification::make()->success()->title('Hello World')->send();
44+
// }),
45+
// // ViewAction::make(),
46+
// // EditAction::make(),
47+
// ActionGroup::make([
48+
//
49+
// ViewAction::make(),
50+
// EditAction::make(),
51+
// ]),
52+
// DeleteAction::make(),
53+
// ];
54+
// }
55+
// OR OVERRIDE FOLLOWING METHODS
56+
//protected function hasDeleteAction(): bool
57+
//{
58+
// return true;
59+
//}
60+
//protected function hasEditAction(): bool
61+
//{
62+
// return true;
63+
//}
64+
//protected function hasViewAction(): bool
65+
//{
66+
// return true;
67+
//}
1868
}

0 commit comments

Comments
 (0)