-
-
Save mstaack/ee392c132c51886d177d9c67017c35b0 to your computer and use it in GitHub Desktop.
Using Nova::sortResourcesBy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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, [ | |
'[email protected]', | |
]); | |
}); | |
} | |
/** | |
* 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; | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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