Skip to content

Commit 899a8e7

Browse files
committed
Scope menu items to menu
1 parent c9adf07 commit 899a8e7

File tree

3 files changed

+998
-5
lines changed

3 files changed

+998
-5
lines changed

src/Models/MenuItem.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,9 @@ public static function getTreeLabelAttribute(): string
113113
{
114114
return 'label';
115115
}
116+
117+
public function getScopeAttributes(): array
118+
{
119+
return ['menu_id'];
120+
}
116121
}

src/Resources/MenuResource/Pages/ManageMenuItems.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function mount(): void
2929
parent::mount();
3030

3131
$menuModelClass = MenuResource::getModel();
32-
$recordId = request()->route('record');
32+
$recordId = static::getMenuRecordId();
3333
$this->record = app($menuModelClass)->findOrFail($recordId);
3434
}
3535

@@ -47,14 +47,15 @@ public static function route(string $path): PageRegistration
4747
);
4848
}
4949

50-
public static function getModel(): string|QueryBuilder
50+
protected static function getMenuRecordId(): int
5151
{
52-
return FilamentFlexibleContentBlockPages::config()->getMenuItemModel();
52+
return request()->route('record');
5353
}
5454

55-
public function getTreeQuery()
55+
public static function getModel(): string|QueryBuilder
5656
{
57-
return static::getModel()::where('menu_id', $this->record->id);
57+
return FilamentFlexibleContentBlockPages::config()->getMenuItemModel()
58+
::scoped(['menu_id' => static::getMenuRecordId()]);
5859
}
5960

6061
public function getTitle(): string

0 commit comments

Comments
 (0)