File tree Expand file tree Collapse file tree 5 files changed +52
-2
lines changed
Expand file tree Collapse file tree 5 files changed +52
-2
lines changed Original file line number Diff line number Diff line change 77 'column_name ' => [
88 'order ' => 'order ' ,
99 'parent ' => 'parent_id ' ,
10- 'depth ' => 'depth ' ,
10+ 'title ' => 'title ' ,
1111 ],
1212 /**
1313 * Tree model default parent key
Original file line number Diff line number Diff line change @@ -14,6 +14,13 @@ trait ModelTree
1414 SupportTranslation::handleTranslatable as traitHandleTranslatable;
1515 }
1616
17+ public function initializeModelTree ()
18+ {
19+ $ this ->fillable [] = $ this ->determineOrderColumnName ();
20+ $ this ->fillable [] = $ this ->determineParentColumnName ();
21+ $ this ->fillable [] = $ this ->determineTitleColumnName ();
22+ }
23+
1724 /**
1825 * Boot the bootable traits on the model.
1926 */
@@ -85,7 +92,7 @@ public function determineParentColumnName() : string
8592
8693 public function determineTitleColumnName () : string
8794 {
88- return ' title ' ;
95+ return Utils:: titleColumnName () ;
8996 }
9097
9198 public static function defaultParentKey ()
Original file line number Diff line number Diff line change 33namespace SolutionForest \FilamentTree ;
44
55use Filament \PluginServiceProvider ;
6+ use Illuminate \Database \Schema \Blueprint ;
67use Livewire \Livewire ;
8+ use SolutionForest \FilamentTree \Macros \BlueprintMarcos ;
79use Spatie \LaravelPackageTools \Package ;
810
911class FilamentTreeServiceProvider extends PluginServiceProvider
@@ -30,4 +32,16 @@ public function configurePackage(Package $package): void
3032 Commands \MakeTreeWidgetCommand::class,
3133 ]);
3234 }
35+
36+ public function boot ()
37+ {
38+ parent ::boot ();
39+
40+ $ this ->registerBlueprintMacros ();
41+ }
42+
43+ protected function registerBlueprintMacros ()
44+ {
45+ Blueprint::mixin (new BlueprintMarcos );
46+ }
3347}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace SolutionForest \FilamentTree \Macros ;
4+
5+ use Illuminate \Database \Schema \Blueprint ;
6+ use SolutionForest \FilamentTree \Support \Utils ;
7+
8+ /**
9+ * @see Blueprint
10+ */
11+ class BlueprintMarcos
12+ {
13+ public function treeColumns ()
14+ {
15+ return function (string $ titleType = 'string ' ) {
16+ $ this ->{$ titleType }(Utils::titleColumnName ());
17+ $ this ->integer (Utils::parentColumnName ())->default (Utils::defaultParentId ());
18+ $ this ->integer (Utils::orderColumnName ())->default (0 )->index ();
19+ };
20+ }
21+ }
Original file line number Diff line number Diff line change @@ -14,11 +14,19 @@ public static function parentColumnName(): string
1414 return config ('filament-tree.column_name.parent ' , 'parent_id ' );
1515 }
1616
17+ /**
18+ * @deprecated Since v1.0.1
19+ */
1720 public static function depthColumnName (): string
1821 {
1922 return config ('filament-tree.column_name.depth ' , 'depth ' );
2023 }
2124
25+ public static function titleColumnName (): string
26+ {
27+ return config ('filament-tree.column_name.title ' , 'title ' );
28+ }
29+
2230 public static function defaultParentId (): int
2331 {
2432 return (int ) config ('filament-tree.default_parent_id ' , -1 );
You can’t perform that action at this time.
0 commit comments