Skip to content

Commit

Permalink
Merge pull request #16 from Log1x/fix/model-url
Browse files Browse the repository at this point in the history
🩹 Add missing URL attribute handling for model menu panels
  • Loading branch information
datlechin authored Aug 17, 2024
2 parents 9959a2a + ad1fede commit b0f6ea4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class Category extends Model implements MenuPanelable

public function getMenuPanelUrlUsing(): callable
{
return fn(self $model) => route('categories.show', $model->slug);
return fn (self $model) => route('categories.show', $model->slug);
}
}
```
Expand Down
10 changes: 10 additions & 0 deletions src/Models/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public function linkable(): MorphTo
return $this->morphTo();
}

protected function url(): Attribute
{
return Attribute::get(function (?string $value) {
return match (true) {
$this->linkable instanceof MenuPanelable => $this->linkable->getMenuPanelUrlUsing()($this->linkable),
default => $value,
};
});
}

protected function type(): Attribute
{
return Attribute::get(function () {
Expand Down

0 comments on commit b0f6ea4

Please sign in to comment.