Skip to content

Commit

Permalink
Merge pull request #67 from Senexis/fix-duplicate-model-titles
Browse files Browse the repository at this point in the history
Fix duplicate model titles causing multiple items being added
  • Loading branch information
datlechin authored Jan 14, 2025
2 parents fcee98a + 402664b commit cb45ccc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/Contracts/MenuPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,16 @@ public function getName(): string;
public function getItems(): array;

public function getSort(): int;

public function getDescription(): ?string;

public function getIcon(): ?string;

public function isCollapsible(): bool;

public function isCollapsed(): bool;

public function isPaginated(): bool;

public function getPerPage(): int;
}
4 changes: 2 additions & 2 deletions src/Livewire/MenuPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function add(): void
$order = $this->menu->menuItems->max('order') ?? 0;

$selectedItems = collect($this->items)
->filter(fn ($item) => in_array($item['title'], $this->data))
->filter(fn ($item) => in_array($item['linkable_id'] ?? $item['title'], $this->data))
->map(function ($item) use (&$order) {
return [
...$item,
Expand All @@ -102,7 +102,7 @@ public function add(): void

public function form(Form $form): Form
{
$items = collect($this->getItems())->mapWithKeys(fn ($item) => [$item['title'] => $item['title']]);
$items = collect($this->getItems())->mapWithKeys(fn ($item) => [$item['linkable_id'] ?? $item['title'] => $item['title']]);

return $form
->schema([
Expand Down

0 comments on commit cb45ccc

Please sign in to comment.