diff --git a/packages/framework/src/Models/NavItem.php b/packages/framework/src/Models/NavItem.php index 8d0cdb55ec5..0e2416814c3 100644 --- a/packages/framework/src/Models/NavItem.php +++ b/packages/framework/src/Models/NavItem.php @@ -62,6 +62,14 @@ public static function toLink(string $href, string $title, int $priority = 500): return (new self(null, $title, $priority, false))->setDestination($href); } + /** + * Create a new navigation menu item leading to a Route model. + */ + public static function toRoute(RouteContract $route, string $title, int $priority = 500): static + { + return new self($route, $title, $priority, false); + } + /** * Resolve a link to the navigation item. * diff --git a/packages/framework/tests/Unit/NavItemTest.php b/packages/framework/tests/Unit/NavItemTest.php index a029ce3711f..b94c5566870 100644 --- a/packages/framework/tests/Unit/NavItemTest.php +++ b/packages/framework/tests/Unit/NavItemTest.php @@ -67,6 +67,17 @@ public function testToLink() $this->assertFalse($item->hidden); } + public function testToRoute() + { + $route = Route::get('index'); + $item = NavItem::toRoute($route, 'foo', 10); + + $this->assertSame($route, $item->route); + $this->assertSame('foo', $item->title); + $this->assertSame(10, $item->priority); + $this->assertFalse($item->hidden); + } + public function testIsCurrentRoute() { $route = Route::get('index');