HEX
Server: LiteSpeed
System: Linux php-prod-3.spaceapp.ru 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: sarli3128 (1010)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /home/marketing.cfbon.ru/public_html/app/Services/AdminMenuBuilder.php
<?php
namespace App\Services;

use App\Enums\UserRole;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str;

class AdminMenuBuilder
{
    private array $menu = [
        [
            'title' => 'Программа лояльности',
            'is_open' => false,
            'child' => [
                [
                    'title' => 'Баллы',
                    'route' => 'loyalty.scores.index',
                    'icon' => 'bi-coin',
                    'is_active' => false,
                ],
                [
                    'title' => 'Пуши',
                    'route' => 'loyalty.push.index',
                    'icon' => 'bi-bell',
                    'is_active' => false,
                ],
            ],
        ],
        [
            'title' => 'Акции',
            'route' => 'promotions.index',
            'is_active' => false,
        ],
        [
            'title' => 'Профиль клиента',
            'route' => 'profile.index',
            'is_active' => false,
        ],
//        [
//            'title' => 'Главная страница сайта',
//            'is_open' => false,
//            'child' => [
//                [
//                    'title' => 'Фото',
//                    'route' => 'site.photo-gallery.index',
//                    'icon' => 'bi-images',
//                    'is_active' => false,
//                ],
//            ],
//        ],
        [
            'title' => 'Фото на сайте',
            'route' => 'site.photo-gallery.index',
            'is_active' => false,
        ],
        [
            'title' => 'Меню',
            'is_open' => false,
            'child' => [
                [
                    'title' => 'Товары',
                    'route' => 'site.menu.products.index',
                    'icon' => 'bi-list-columns',
                    'is_active' => false,
                ],
                [
                    'title' => 'Категории меню',
                    'route' => 'site.menu.categories.index',
                    'icon' => 'bi-bookmarks',
                    'is_active' => false,
                ],
                [
                    'title' => 'Объемы',
                    'route' => 'site.menu.volumes.index',
                    'icon' => 'bi-cup-hot',
                    'is_active' => false,
                ],
            ],
        ],
        [
            'title' => 'Кофейни на картах',
            'route' => 'coffee-shops.index',
            'is_active' => false,
        ],
        [
            'title' => 'Админы',
            'route' => 'admin-user.index',
            'is_active' => false,
            'userRole' => UserRole::ADMIN->value,
        ],
    ];

    public function getMenu(): Collection
    {
        $currentRoute = '/' . Route::getFacadeRoot()->current()->uri();

        return collect($this->menu)->filter(function ($item) {
            if (isset($item['userRole'])) {
                $role = UserRole::tryFrom($item['userRole']);
                if (!$role || !Gate::allows($role)) {
                    return false;
                }
            }
            return true;
        })->map(function ($item) use ($currentRoute) {
            if (isset($item['child'])) {
                foreach ($item['child'] as &$child) {
                    if (Str::startsWith($currentRoute, route($child['route'], [], false))) {
                        $child['is_active'] = true;
                        $item['is_open'] = true;
                    }
                }
                return $item;
            }
            if (Str::startsWith($currentRoute, route($item['route'], [], false))) $item['is_active'] = true;
            return $item;
        });
    }
}