Skip to content

Commit ec64445

Browse files
authored
Merge pull request #216 from hydephp/215-add-a-navitemtoroute-helper
Add a NavItem::toRoute() helper
2 parents 4d48444 + f536688 commit ec64445

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

packages/framework/src/Models/NavItem.php

+8
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ public static function toLink(string $href, string $title, int $priority = 500):
6262
return (new self(null, $title, $priority, false))->setDestination($href);
6363
}
6464

65+
/**
66+
* Create a new navigation menu item leading to a Route model.
67+
*/
68+
public static function toRoute(RouteContract $route, string $title, int $priority = 500): static
69+
{
70+
return new self($route, $title, $priority, false);
71+
}
72+
6573
/**
6674
* Resolve a link to the navigation item.
6775
*

packages/framework/tests/Unit/NavItemTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ public function testToLink()
6767
$this->assertFalse($item->hidden);
6868
}
6969

70+
public function testToRoute()
71+
{
72+
$route = Route::get('index');
73+
$item = NavItem::toRoute($route, 'foo', 10);
74+
75+
$this->assertSame($route, $item->route);
76+
$this->assertSame('foo', $item->title);
77+
$this->assertSame(10, $item->priority);
78+
$this->assertFalse($item->hidden);
79+
}
80+
7081
public function testIsCurrentRoute()
7182
{
7283
$route = Route::get('index');

0 commit comments

Comments
 (0)