Search code examples
phplaravellaravel-5.8laravel-nova

Laravel Nova - Reorder left navigation menu items


In default the ordering of left menu items is in alphabetical order.

My client wants to order those menus manually. Any idea how to make it possible?

enter image description here

Go to answer


Solution

  • There are two ways to achieve this:

    1. By setting priority to Resource
    2. Ordering Resource models in NovaServiceProvider

    1. Priority Method

    • Add priority as in the following code in Resource model:
        public static $priority = 2;
      
    • Then update NovaServiceProvider like this:
      public function boot()
      {
          Nova::sortResourcesBy(function ($resource) {
              return $resource::$priority ?? 9999;
          });
      }
      

    2. Ordering Resource models in NovaServiceProvider

    In NovaServiceProvider, order Resource models like this:

    protected function resources()
    {
        Nova::resources([
            User::class,
            Post::class,
        ]);
     }