bdhabib/laravel-menu
Composer 安装命令:
composer require bdhabib/laravel-menu
包简介
Drag & Drop menu builder like WordPress for Laravel 12.x
关键字:
README 文档
README
Installation
- Run
composer require bdhabib/laravel-menu
- Run publish
php artisan vendor:publish --provider="Bdhabib\LaravelMenu\LaravelMenuServiceProvider"
- Configure (optional) in config/menu.php :
- CUSTOM MIDDLEWARE: You can add you own middleware
- TABLE PREFIX: By default this package will create 2 new tables named "menus" and "menu_items" but you can still add your own table prefix avoiding conflict with existing table
- TABLE NAMES If you want use specific name of tables you have to modify that and the migrations
- Custom routes If you want to edit the route path you can edit the field
- Role Access If you want to enable roles (permissions) on menu items
- Post Model You can add your own post model. Default is Post
- Category Model You can add your own category model. Default is Category
- Post Title Column You can add your own post model title column. Default is title
- Category Title Column You can add your own category model title column. Default is name
- Run migrate
php artisan migrate
DONE
Laravel Menu Usage Example - displays the UI
On your view blade file
@extends('app') @section('contents') {!! LaravelMenu::render() !!} @endsection // Recommended to Add Font Awesome CDN In Your Backend Header //maxcdn.bootstrapcdn.com/font-awesome/6.1.1/css/font-awesome.min.css //YOU MUST HAVE JQUERY LOADED BEFORE menu scripts @push('scripts') {!! LaravelMenu::scripts() !!} @endpush
Using The Model
Call the model class
use Bdhabib\LaravelMenu\Models\Menus; use Bdhabib\LaravelMenu\Models\MenuItems;
Menu Usage Example (a)
A basic two-level menu can be displayed in your blade template
Using Model Class
/* get menu by id*/ $menu = Menus::find(1); /* or by name */ $menu = Menus::where('name','Your Menu name')->first(); /* or get menu by name and the items with EAGER LOADING (RECOMENDED for better performance and less query call)*/ $menu = Menus::where('name','Your Menu name')->with('items')->first(); /*or by id */ $menu = Menus::where('id', 1)->with('items')->first(); //you can access by model result $primary_menu = $menu->items; //or you can convert it to array $primary_menu = $menu->items->toArray();
or Using helper
// Using Helper $primary_menu = LaravelMenu::getByName('Primary'); //return array
Menu Usage Example (b)
Now inside your blade template file place the menu using this simple example
<nav class="" id="navbar">
<div class="navbar__menu container">
<ul>
@if ($primary_menu)
@foreach ($primary_menu as $menu)
<li>
<a href="{{ $menu['link'] }}" title="{{ $menu['label'] }}">{{ $menu['label'] }}</a>
@if ($menu['child'])
<ul class="sub-menu">
@foreach ($menu['child'] as $child)
<li class=""><a href="{{ $child['link'] }}"
title="">{{ $child['label'] }}</a>
</li>
@endforeach
</ul><!-- /.sub-menu -->
@endif
</li>
@endforeach
@endif
</div>
</nav>
HELPERS
Get Menu Items By Menu ID
use Bdhabib\LaravelMenu\Facades\LaravelMenu; ... /* Parameter: Menu ID Return: Array */ $menuList = LaravelMenu::get(1);
Get Menu Items By Menu Name
In this example, you must have a menu named Admin
use Bdhabib\LaravelMenu\Facades\LaravelMenu; ... /* Parameter: Menu ID Return: Array */ $menuList = LaravelMenu::getByName('Admin');
Customization
you can edit the menu interface in resources/views/vendor/laravel-menu/menu.blade.php
Credits
- wmenu laravel package menu like wordpress
Compatibility
- Tested with laravel 11.x
- Work only laravel 11.x
bdhabib/laravel-menu 适用场景与选型建议
bdhabib/laravel-menu 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 905 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 03 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「menu」 「wordpress」 「builder」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bdhabib/laravel-menu 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bdhabib/laravel-menu 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bdhabib/laravel-menu 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Symfony extension to get active class base on current bundle/controller/action
A Sphinx Query Builder extension for the Laravel Database package
Anax Database Active Record module for model classes.
A simple package to create tables in Discord messages.
Create mail from controller action render
Yii2 DynaTree Menu widget uses Dynamic tree view control jquery.dynatree.js
统计信息
- 总下载量: 905
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-17