Laravel Nova - Reorder left navigation menu items

A cleaner way and tested on latest Nova 3.x. Also, this has been added to Nova since version 2.10+ All you need to do is add a static property on your nova classes. For example Clients will be:

/**
 * The side nav menu order.
 *
 * @var int
 */
public static $priority = 2;

Then after that you can use the NovaServiceProvider to tell nova to use your custom ordering. You can place the code in the boot method

public function boot()
{
    Nova::sortResourcesBy(function ($resource) {
        return $resource::$priority ?? 9999;
    });
}

**Reference Nova Private Repo


You can do it in

App\Providers\NovaServiceProvider.php

add a method resources() and register the resources manually like

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

Alternate

There is another way mentioned in this gist, this seems good too, but official documentation has no mention of it yet.

Resource

<?php

namespace App\Nova;

class User extends Resource
{
    /**
     * The model the resource corresponds to.
     *
     * @var string
     */
    public static $model = 'App\\User';

    /**
     * Custom priority level of the resource.
     *
     * @var int
     */
    public static $priority = 1;

    // ...
}

and in NovaServiceProvider

<?php

namespace App\Providers;

use Laravel\Nova\Nova;
use Laravel\Nova\Cards\Help;
use Illuminate\Support\Facades\Gate;
use Laravel\Nova\NovaApplicationServiceProvider;

class NovaServiceProvider extends NovaApplicationServiceProvider
{
   /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        Nova::sortResourcesBy(function ($resource) {
            return $resource::$priority ?? 99999;
        });
    }
}

This way you set priority of resource and based on priority you render the resource.


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,
    ]);
 }