Created
December 31, 2019 10:49
-
-
Save nasrulhazim/43dad32c469736e85ba1be73195d7132 to your computer and use it in GitHub Desktop.
Register Dashboard Menu in Nova
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 Illuminate\Support\Facades\Gate; | |
use Laravel\Nova\Nova; | |
use Laravel\Nova\NovaApplicationServiceProvider; | |
class NovaServiceProvider extends NovaApplicationServiceProvider | |
{ | |
/** | |
* Bootstrap any application services. | |
*/ | |
public function boot() | |
{ | |
parent::boot(); | |
Nova::serving(function () { | |
$tools = collect(Nova::$tools); | |
$resource = $tools->pull(1); | |
$tools->push($resource); | |
Nova::$tools = $tools->all(); | |
}); | |
} | |
/** | |
* Get the tools that should be listed in the Nova sidebar. | |
* | |
* @return array | |
*/ | |
public function tools() | |
{ | |
return []; | |
} | |
/** | |
* Register any application services. | |
*/ | |
public function register() | |
{ | |
} | |
/** | |
* Register the Nova routes. | |
*/ | |
protected function routes() | |
{ | |
Nova::routes() | |
->withAuthenticationRoutes() | |
->withPasswordResetRoutes() | |
->register(); | |
} | |
/** | |
* Register the Nova gate. | |
* | |
* This gate determines who can access Nova in non-local environments. | |
*/ | |
protected function gate() | |
{ | |
Gate::define('viewNova', function ($user) { | |
return in_array($user->email, \App\User::all()->pluck('email')->toArray()); | |
}); | |
} | |
/** | |
* Get the cards that should be displayed on the Nova dashboard. | |
* | |
* @return array | |
*/ | |
protected function cards() | |
{ | |
return [ | |
(new \NasrulHazim\DashboardMenu\DashboardMenu)->canSee(function ($request) { | |
return true; | |
})->getMenus(), | |
]; | |
} | |
/** | |
* Get the extra dashboards that should be displayed on the Nova dashboard. | |
* | |
* @return array | |
*/ | |
protected function dashboards() | |
{ | |
return []; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment