/home/bdqbpbxa/dev-subdomains/api-uniferx.goodface.com.ua/app/Providers/NovaServiceProvider.php
<?php

namespace App\Providers;

use App\Nova\Catalog;
use App\Nova\Country;
use App\Nova\Crop;
use App\Nova\Dashboards\Main;
use App\Nova\Employee;
use App\Nova\Flyer;
use App\Nova\Language;
use App\Nova\Page;
use App\Nova\Post;
use App\Nova\Product;
use App\Nova\Vacancy;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Laravel\Nova\Menu\MenuGroup;
use Laravel\Nova\Menu\MenuItem;
use Laravel\Nova\Menu\MenuSection;
use Laravel\Nova\Nova;
use Laravel\Nova\NovaApplicationServiceProvider;
use Oneduo\NovaFileManager\NovaFileManager;

class NovaServiceProvider extends NovaApplicationServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();
        Nova::mainMenu(function (Request $request) {
            $generalSetting = \App\Models\Page::query()->where('name', 'General Translations')->first();
            return [
                MenuItem::make('General Translations')
                    ->path("/resources/pages/".($generalSetting?->id)),
                MenuGroup::make(__('Pages'), [
                    MenuItem::resource(Page::class),
                ])->canSee(function () {
                    return $this->checkCountryLang();
                }),
                MenuGroup::make(__('Blog'), [
                    MenuItem::resource(Post::class),
                ])->canSee(function () {
                    return $this->checkCountryLang();
                }),
                MenuGroup::make(__('Career'), [
                    MenuItem::resource(Vacancy::class),
                ])->canSee(function () {
                    return $this->checkCountryLang();
                }),
                MenuGroup::make(__('Employees'), [
                    MenuItem::resource(Employee::class),
                ])->canSee(function () {
                    return $this->checkCountryLang();
                }),
                MenuGroup::make(__('Resources'), [
                    MenuItem::resource(Crop::class),
                ])->canSee(function () {
                    return $this->checkCountryLang();
                }),
                MenuGroup::make(__('Products'), [
                    MenuItem::resource(Product::class),
                ])->canSee(function () {
                    return $this->checkCountryLang();
                }),
                MenuGroup::make(__('Catalogs'), [
                    MenuItem::resource(Catalog::class),
                    MenuItem::resource(Flyer::class),
                ])->canSee(function () {
                    return $this->checkCountryLang();
                }),
                MenuGroup::make(__('Localizations'), [
                    MenuItem::resource(Language::class),
                    MenuItem::resource(Country::class)->canSee(function () {
                        return \App\Models\Language::query()->count();
                    }),
                ]),
            ];
        });
    }

    /**
     * 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, [
                //
            ]);
        });
    }

    /**
     * Get the dashboards that should be listed in the Nova sidebar.
     *
     * @return array
     */
    protected function dashboards()
    {
        return [
            new \App\Nova\Dashboards\Main,
        ];
    }

    /**
     * Get the tools that should be listed in the Nova sidebar.
     *
     * @return array
     */
    public function tools()
    {
        return [
            NovaFileManager::make(),
        ];
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        Nova::initialPath('/resources/pages');
    }
    public function checkCountryLang(): bool
    {
        $languages = \App\Models\Language::query()->count();
        $countries = \App\Models\Country::query()->count();
        if ($languages & $countries) {
            return true;
        }
        return false;
    }
}