File tree Expand file tree Collapse file tree 2 files changed +4
-2
lines changed
Expand file tree Collapse file tree 2 files changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -91,7 +91,8 @@ public function updateTree(?array $list = null): array
9191 $ records = $ this ->getRecords ()->keyBy (fn ($ record ) => $ record ->getAttributeValue ($ record ->getKeyName ()));
9292
9393 $ unnestedArr = [];
94- $ this ->unnestArray ($ unnestedArr , $ list , Utils::defaultParentId ());
94+ $ defaultParentId = Utils::defaultParentId ();
95+ $ this ->unnestArray ($ unnestedArr , $ list , $ defaultParentId );
9596 $ unnestedArrData = collect ($ unnestedArr )
9697 ->map (fn (array $ data , $ id ) => ['data ' => $ data , 'model ' => $ records ->get ($ id )])
9798 ->filter (fn (array $ arr ) => !is_null ($ arr ['model ' ]));
@@ -101,6 +102,7 @@ public function updateTree(?array $list = null): array
101102 if ($ model instanceof Model) {
102103 $ parentColumnName = method_exists ($ model , 'determineParentColumnName ' ) ? $ model ->determineParentColumnName () : Utils::parentColumnName ();
103104 $ orderColumnName = method_exists ($ model , 'determineOrderColumnName ' ) ? $ model ->determineOrderColumnName () : Utils::orderColumnName ();
105+ $ newParentId = $ newParentId === $ defaultParentId && method_exists ($ model , 'defaultParentKey ' ) ? $ model ::defaultParentKey () : $ newParentId ;
104106
105107 $ model ->{$ parentColumnName } = $ newParentId ;
106108 $ model ->{$ orderColumnName } = $ newOrder ;
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ public function initializeModelTree()
2727 public static function bootModelTree ()
2828 {
2929 static ::saving (function (Model $ model ) {
30- if (empty ($ model ->{$ model ->determineParentColumnName ()}) || $ model ->{$ model ->determineParentColumnName ()} === 0 ) {
30+ if (empty ($ model ->{$ model ->determineParentColumnName ()}) || $ model ->{$ model ->determineParentColumnName ()} === - 1 ) {
3131 $ model ->{$ model ->determineParentColumnName ()} = static ::defaultParentKey ();
3232 }
3333 if (empty ($ model ->{$ model ->determineOrderColumnName ()}) || $ model ->{$ model ->determineOrderColumnName ()} === 0 ) {
You can’t perform that action at this time.
0 commit comments