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?
Go to answer
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With