Files
online.tbbank.gov.tm-larave…/app/Providers/NovaServiceProvider.php
2024-03-27 14:22:09 +05:00

146 lines
3.5 KiB
PHP

<?php
namespace App\Providers;
use App\Nova\Dashboards\Main;
use App\Nova\User;
use App\Repos\System\Nova\NovaMenuRepo;
use App\Repos\System\Nova\NovaRepo;
use Eolica\NovaLocaleSwitcher\LocaleSwitcher;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Laravel\Nova\Events\ServingNova;
use Laravel\Nova\Fields\Date;
use Laravel\Nova\Fields\DateTime;
use Laravel\Nova\Fields\Filters\DateTimeFilter;
use Laravel\Nova\Menu\Menu;
use Laravel\Nova\Menu\MenuItem;
use Laravel\Nova\Nova;
use Laravel\Nova\NovaApplicationServiceProvider;
use Spatie\BackupTool\BackupTool;
use Stepanenko3\LogsTool\LogsTool;
class NovaServiceProvider extends NovaApplicationServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
Nova::initialPath(NovaRepo::initialPath());
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
parent::boot();
Nova::withBreadcrumbs();
Nova::footer(NovaRepo::footer());
$this->setupNavigation();
$this->setupUserNavigation();
$this->setupUserSettings();
$this->setupAssets();
$this->setupFieldMacros();
}
/**
* Register the Nova routes.
*/
protected function routes(): void
{
Nova::routes()
->withAuthenticationRoutes()
->withPasswordResetRoutes()
->register();
}
/**
* Register the Nova gate.
*
* This gate determines who can access Nova in non-local environments.
*/
protected function gate(): void
{
Gate::define('viewNova', NovaRepo::viewNova());
}
/**
* Get the dashboards that should be listed in the Nova sidebar.
*/
protected function dashboards(): array
{
return [
new Main,
];
}
/**
* Get the tools that should be listed in the Nova sidebar.
*/
public function tools(): array
{
return [
LocaleSwitcher::make()
->setLocales(config('app.locales'))
->onSwitchLocale(NovaRepo::localeSwitcherSave()),
BackupTool::make()
->canSee(NovaRepo::isSuperAdmin()),
LogsTool::make()
->canSee(NovaRepo::isMe())
->canDownload(NovaRepo::isMe())
->canDelete(NovaRepo::isMe()),
];
}
/**
* Setup navigation
*/
public function setupNavigation(): void
{
Nova::mainMenu(fn (Request $request) => NovaMenuRepo::items($request));
}
/**
* Setup user navigation (dropdown).
*/
public function setupUserNavigation(): void
{
Nova::userMenu(function (Request $request, Menu $menu) {
$menu->prepend(MenuItem::make(__('My Profile'), $request->user()->profilePage()));
return $menu;
});
}
/**
* Setup user settings
*/
public function setupUserSettings(): void
{
Nova::serving(fn (ServingNova $event) => NovaRepo::serving($event));
}
/**
* Setup Assets
*/
public function setupAssets(): void
{
Nova::style('additional', resource_path('css/vendor/nova/css/additional.css'));
}
/**
* Setup macros of fields
*/
public function setupFieldMacros(): void
{
Date::macro('toTurkmenFormat', fn () => $this->displayUsing(fn ($value) => $value?->format('d.m.Y')));
DateTime::macro('turkmenDateTime', fn () => $this->displayUsing(fn ($value) => $value?->format('H:i, d.m.Y')));
}
}