sukristyan/laravel-menu-wrapper 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sukristyan/laravel-menu-wrapper

最新稳定版本:1.0.4

Composer 安装命令:

composer require sukristyan/laravel-menu-wrapper

包简介

A lightweight Laravel package to simplify building dynamic and structured menus in your applications.

README 文档

README

Laravel Menu Wrapper is a lightweight package that helps you manage dynamic menus in your Laravel app with less effort.

Simply put, this package automatically generates an array of menus based on what you define.

Tested on Laravel 10.x, 11.x, and 12.x — works successfully without any issues.

Installation

Using Composer (recommended):

cd your-laravel-project
composer require sukristyan/laravel-menu-wrapper

After the installation is complete, the provider and configuration files will be published automatically.

Configuration

Currently, there are only 2 configuration items.

Group As (group_as)

Values: item or key.

This setting determines how your menus will be grouped.

key means that your group label will be used as the array key. Your defined menu will look like this:

[
    'Group Name' => [
        [
            'label' => 'Menu #1',
        ],
        [
            'label' => 'Menu #2',
        ]
    ],
    ...
]

item means that your group label will be included in the array as group_name, and your defined menus will be inserted under childs. Your menu will look like this:

[
    [
        'group_name' => 'Group Name',
        'childs' => [
            [
                'label' => 'Menu #1',
            ],
            [
                'label' => 'Menu #2',
            ],
        ],
    ],
    ...
]

Populated Items (populated_items)

Here, you can define what you want to collect from the 'Illuminate\Routing\Route', or add custom identifiers to help integrate the menu into your application.

'populate_items' => function (Route $route) {
    return [
        'route_name' => $route->getName(),
        'type' => 'children'
    ];
}

Usage

NOTE: All collected data will follow what you define in config/laravel-menu-wrapper.php.

Go to your 'routes/web.php', and add the menu('Menu Label', 'Group Label') function to your route:

Route::get('index', [DashboardController::class, 'index'])
    ->name('index')
    ->menu('Dashboard');

After that, you can run php artisan menu:list to show all your menus. You can also get all menus using this code:

app('sukristyan.menu')->all();

You can parse the resulting menu array and use it anywhere in your project.

You can directly use it in a foreach loop, or create a custom page to manage the menu — allowing administrators to add or remove menu items for users.

$menus = app('sukristyan.menu')->all();

foreach ($menus as $menu) {
    ...
}

License

The sukristyan/laravel-menu-wrapper package is open-sourced software licensed under the MIT license.

统计信息

  • 总下载量: 15
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-03