Skip to content

Instantly share code, notes, and snippets.

@mstaack
Forked from jbrooksuk/NovaServiceProvider.php
Created February 17, 2021 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mstaack/ee392c132c51886d177d9c67017c35b0 to your computer and use it in GitHub Desktop.
Save mstaack/ee392c132c51886d177d9c67017c35b0 to your computer and use it in GitHub Desktop.
Using Nova::sortResourcesBy
<?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
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
parent::boot();
}
/**
* Register the Nova routes.
*
* @return void
*/
protected function routes()
{
Nova::routes()
->withAuthenticationRoutes()
->withPasswordResetRoutes()
->register();
}
/**
* Register the Nova gate.
*
* This gate determines who can access Nova in non-local environments.
*
* @return void
*/
protected function gate()
{
Gate::define('viewNova', function ($user) {
return in_array($user->email, [
'james@laravel.com',
]);
});
}
/**
* Get the cards that should be displayed on the Nova dashboard.
*
* @return array
*/
protected function cards()
{
return [
new Help,
];
}
/**
* Get the tools that should be listed in the Nova sidebar.
*
* @return array
*/
public function tools()
{
return [];
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
Nova::sortResourcesBy(function ($resource) {
return $resource::$priority ?? 99999;
});
}
}
<?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;
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment