Menus
Nova menus provide a convenient way to customize the main and user menus.
Overview
By default, Nova’s main left-side navigation menu displays all of your application’s dashboards, resources, and any custom tools you have registered.
When rendering the main menu, Nova will order your dashboards according to the order in which they are returned by the dashboards
method within your application’s App\Providers\NovaServiceProvider
class.
Nova will also automatically group your resources under the default “Resources” menu section according to the group
property defined in the Resource
class. In addition, any custom tools you have registered will be listed in the order they are defined within your application’s NovaServiceProvider
.
Customizing the Main Menu
While Nova’s default main menu is sufficient for most applications, there are times you may wish to completely customize the menu based on your own preferences. For that reason, Nova allows you to define your own main menu via the Nova::mainMenu
method. Typically, this method should be invoked within the boot
method of your application’s App\Providers\NovaServiceProvider
class:
Customizing the User Menu
Nova also allows you to customize the “user” menu found in the top-right navigation area. You can customize Nova’s user menu by calling the Nova::userMenu
method. This method is typically invoked within the boot
method of your application’s App\Providers\NovaServiceProvider
:
By default, Nova is configured to display a “logout” link in the user menu. This link may not be removed.
Nova’s user menu only supports MenuItem
objects. Using MenuSection
or MenuGroup
inside the user menu will throw an Exception
.
Appending / Prepending to the Menu
You may call the append
and prepend
methods on a Menu
instance to prepend or append new items to the. These methods are typically most helpful when customizing the user menu, since you often do not want to completely replace the existing menu:
Menu Sections
Menu sections represent a top-level navigation item and are typically displayed with an corresponding icon representing the types of items in the menu. You can create a new menu section by calling the MenuSection::make
method. This method accepts the name of the menu section and array of menu groups / items that should be placed within the section:
Instead of displaying a list of links, you may indicate that a menu section should just be a large, emphasized link to another location. To accomplish this, you may invoke the path
method when defining the menu section:
For convenience, if you are only creating a menu section to serve as a large, emphasized link to a Nova dashboard, you may invoke the MenuSection::dashboard
method:
Since you will often be creating links to Nova resources, you may use the resource
method to quickly create a link to the appropriate path for a given resource:
Similarly, you may create links to Nova lenses via the lens
method:
Menu sections that are defined as collapsable
do not support also being a link. Calling path
on a menu section when it’s collapseable
will result in no link being shown.
Menu Section Icons
You can customize the icon displayed for your menu section by invoking the icon
method when defining the menu section:
Nova utilizes the free Heroicons icon set by Steve Schoger. Therefore, you may simply specify the name of one of these icons when providing the icon name to the icon
method.
Menu Section Badges
You may add visual badges to your menu section by calling the withBadge
method on your MenuSection
and specifying the options for the badge:
Conditional Badges
Using the withBadgeIf
method, you may conditionally add a badge only if a given condition is met:
Collapsable Menu Sections
You may make your menu sections collapsable by invoking the collapsable
method when defining the menu section. For convenience, Nova will remember the open state for the section between requests:
Menu Groups
Sometimes you may need another logical level between your menu sections and menu items. In this case, menu groups are the perfect solution. Menu groups allow you to group menu items under their own emphasized heading:
Collapsable Menu Groups
You may make your menu groups collapsable by invoking the collapsable
method on the group. For convenience, Nova will remember the open state for the group between requests:
Menu Items
Menu items represent the different types of links to areas inside and outside of your application that may be added to a custom Nova menu. Nova ships with several convenience methods for creating different types of menu items.
First, to create a link to an internal area of Nova, you may call the link
factory method on the MenuItem
class:
Resource Menu Items
Since you will often be creating links to Nova resources, you may use the resource
method to quickly create a link to the appropriate path for a given resource:
Filtered Resource Menu Items
To create a link to a Nova resource with a predefined filter applied, you can use the filter
method, passing in an instance of the filter and the value it should receive. Since filters can be used with multiple resources, you must also pass a name for the menu item, since it cannot be automatically generated:
Using Multiple Filters With Filtered Resource Menu Items
You may also pass multiple filters to a resource menu item. For instance, let’s imagine you wanted to create a menu item that linked to your User
resource, showing users that have an email ending in @laravel.com
and that also have a status of active
:
Passing Constructor Parameters to Filtered Resource Menu Items
Nova filters may also receive constructor parameters to enable convenient re-use of your filters across resources. To pass the parameters when creating a filtered resource menu item, just provide them to the filter’s make
method:
Lens Menu Items
Similar to resource items, you may create links to Nova lenses via the lens
method:
Dashboard Menu Items
You may also create a link to any of your custom Nova dashboards by calling the dashboard
factory method:
External Link Menu Items
To create a link that directs the user to a location that is totally outside of your Nova application, you may use the externalLink
factory method:
To specify an external link should open within a separate tab, you may call the openInNewTab
method on your menu item:
You may also call the method
helper to pass in the HTTP method, request data, and any HTTP headers that should be sent to your application when the link is clicked. This is typically useful for items like logout links, which should be POST
requests:
Menu Item Badges
You may add visual badges to your menu item by calling the withBadge
method on your MenuItem
and specifying the options for the badge:
Conditional Badges
You may also conditionally add badge only if the condition is met.
Authorizing Menu Items
You may use the canSee
method to determine if a menu item should be displayed for the currently authenticated user: