File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ class="space-y-6"
26
26
@else
27
27
<!-- Tree Items -->
28
28
<div class =" space-y-2" id =" menu-items-container" wire:key =" tree-{{ $refreshKey } }" >
29
- @foreach ($this -> record -> menuItems () -> with ([ ' children ' , ' linkable ' ]) -> whereNull ( ' parent_id ' ) -> orderBy ( ' _lft ' ) -> get () as $item )
29
+ @foreach ($this -> getTreeItems () as $item )
30
30
@livewire (' filament-flexible-content-block-pages::menu-tree-item' , [
31
31
' item' => $item ,
32
32
' maxDepth' => $this -> getMaxDepth ()
Original file line number Diff line number Diff line change @@ -32,6 +32,8 @@ class ManageMenuItems extends Page implements HasActions, HasForms
32
32
public mixed $ record ;
33
33
34
34
public $ refreshKey = 0 ;
35
+
36
+ public $ menuItems = null ;
35
37
36
38
public function mount (int |string $ record ): void
37
39
{
@@ -72,6 +74,16 @@ public function getMenuItems(): array
72
74
return $ this ->buildTree ($ items ->toArray ());
73
75
}
74
76
77
+ public function getTreeItems ()
78
+ {
79
+ // Force fresh query every time
80
+ return $ this ->record ->menuItems ()
81
+ ->with (['children ' , 'linkable ' ])
82
+ ->whereNull ('parent_id ' )
83
+ ->orderBy ('_lft ' )
84
+ ->get ();
85
+ }
86
+
75
87
protected function buildTree (array $ items , $ parentId = null ): array
76
88
{
77
89
$ tree = [];
@@ -921,6 +933,8 @@ public function moveItemUp(int $itemId): void
921
933
$ previousSibling = $ item ->getPrevSibling ();
922
934
if ($ previousSibling ) {
923
935
$ item ->beforeNode ($ previousSibling )->save ();
936
+
937
+ // Refresh the tree to show new order
924
938
$ this ->refreshTree ();
925
939
926
940
Notification::make ()
@@ -952,6 +966,8 @@ public function moveItemDown(int $itemId): void
952
966
$ nextSibling = $ item ->getNextSibling ();
953
967
if ($ nextSibling ) {
954
968
$ item ->afterNode ($ nextSibling )->save ();
969
+
970
+ // Refresh the tree to show new order
955
971
$ this ->refreshTree ();
956
972
957
973
Notification::make ()
You can’t perform that action at this time.
0 commit comments