Skip to content

Commit 90a2032

Browse files
authored
feat: connect custom model to page controller (#99)
* feat: connect custom model to page controller * fix: add title * docs: add description
1 parent 7338cf7 commit 90a2032

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Http/Controllers/Pages/PageController.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class PageController extends Controller
1818

1919
protected bool $currentPage = false;
2020

21+
protected string $model = Menu::class;
22+
2123
public function __construct(
2224
protected ?int $pageId = null
2325
) {
@@ -52,10 +54,17 @@ public function id(): int
5254
return $this->pageId;
5355
}
5456

57+
/**
58+
* menuItem
59+
*
60+
* This will fetch the Menu model for the current page.
61+
* You can subclass Menu and add a custom model to the
62+
* $model property to use a custom model.
63+
*/
5564
protected function menuItem(): Menu
5665
{
5766
if ($this->menuItem === null) {
58-
$this->menuItem = Menu::whereId($this->id())->firstOrFail();
67+
$this->menuItem = $this->model::whereId($this->id())->firstOrFail();
5968
}
6069

6170
return $this->menuItem;

0 commit comments

Comments
 (0)