Skip to content

Commit

Permalink
fix duplicate db queries
Browse files Browse the repository at this point in the history
  • Loading branch information
iRaziul authored Dec 26, 2024
1 parent a6490cf commit fcec82c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Concerns/HasLocationAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

trait HasLocationAction
{
protected ?Collection $menus = null;

protected ?Collection $menuLocations = null;

public function getLocationAction(): Action
Expand Down Expand Up @@ -70,7 +72,7 @@ public function getLocationAction(): Action
->label(__('filament-menu-builder::menu-builder.actions.locations.form.menu.label'))
->searchable()
->hiddenLabel($key !== $this->getRegisteredLocations()->keys()->first())
->options($this->getModel()::all()->pluck('name', 'id')->all()),
->options($this->getMenus()->pluck('name', 'id')->all()),
]),
)->all() ?: [
Components\View::make('filament-tables::components.empty-state.index')
Expand All @@ -81,6 +83,11 @@ public function getLocationAction(): Action
]);
}

protected function getMenus(): Collection
{
return $this->menus ??= FilamentMenuBuilderPlugin::get()->getMenuModel()::all();
}

protected function getMenuLocations(): Collection
{
return $this->menuLocations ??= FilamentMenuBuilderPlugin::get()->getMenuLocationModel()::all();
Expand Down

0 comments on commit fcec82c

Please sign in to comment.