定制 smartystudio/laravelmenu 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

smartystudio/laravelmenu

最新稳定版本:v0.1

Composer 安装命令:

composer require smartystudio/laravelmenu

包简介

Drag and drop menu generator for Laravel.

README 文档

README

An admin interface for Laravel to easily add, edit or remove Menus.

Install

  1. In your terminal:
composer require smartystudio/laravelmenu

Step 2 & 3 are optional if you are using laravel 5.5

  1. If your Laravel version does not have package autodiscovery then add the service provider to your config/app.php file:
SmartyStudio\LaravelMenu\MenuServiceProvider::class,
  1. Add facade in the file config/app.php (optional on laravel 5.5):
'Menu' => SmartyStudio\LaravelMenu\Facades\Menu::class,
  1. Publish the config file & run the migrations.
php artisan vendor:publish --provider="SmartyStudio\LaravelMenu\MenuServiceProvider"
  1. Configure (optional) in config/laravelmenu.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
  1. Run the database migrations:
php artisan migrate

DONE!

Menu Builder Usage Example - displays the builder

On your view blade file

@extends('app')

@section('contents')
    {!! Menu::render() !!}
@endsection

You must have jQuery loaded before menu scripts

@push('scripts')
    {!! Menu::scripts() !!}
@endpush

Using the Model

Call the model class:

use SmartyStudio\LaravelMenu\Models\Menu;
use SmartyStudio\LaravelMenu\Models\MenuItem;

Menu Usage Example (a)

A basic two-level menu can be displayed in your blade template.

Using Model class

// Get menu by ID
$menu = Menu::find(1);

// Get menu by Name
$menu = Menu::where('name','Test Menu')->first();

/**
 * Get menu by Name and the Items with eager loading.
 * This is RECOMENDED for better performance and less query calls.
 */
$menu = Menu::where('name','Test Menu')->with('items')->first();

// Get menu by ID
$menu = Menu::where('id', 1)->with('items')->first();

// Access by Model result
$public_menu = $menu->items;

// Convert it to Array
$public_menu = $menu->items->toArray();

Using Helper class

// Using Helper 
$public_menu = Menu::getByName('Public'); // return array

Menu Usage Example (b)

Now inside your blade template file, place the menu using this simple example:

<div class="nav-wrap">
    <div class="btn-menu">
        <span></span>
    </div><!-- // mobile menu button -->
    <nav id="mainnav" class="mainnav">
        @if($public_menu)
            <ul class="menu">
                @foreach($public_menu as $menu)
                    <li class="">
                        <a href="{{ $menu['link'] }}" title="">{{ $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
            <!-- empty -->
        @endif
        </ul><!-- /.menu -->
    </nav><!-- /#mainnav -->
 </div><!-- /.nav-wrap -->

HELPERS

Get Menu Items By Menu ID

use SmartyStudio\LaravelMenu\Facades\Menu;
...
/**
 * Parameter: Menu ID
 * Return:    Array
 */
$menuList = Menu::get(1);

Get Menu Items By Menu Name

In this example, you must have a menu named Admin

use SmartyStudio\LaravelMenu\Facades\Menu;
...
/**
 * Parameter: Menu ID
 * Return:    Array
 */
$menuList = Menu::getByName('Admin');

Customization of the menu

You can publish and edit the menu layout in resources/views/vendor/smartystudio/laravelmenu/menu.blade.php

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

// TODO

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email us instead of using the issue tracker.

Credits

  • Martin Nestorov - Web Developer @ Smarty Studio.
  • All Contributors

License

The SmartyStudio\LaravelMenu is open-source software licensed under the MIT license.

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: Blade

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-12-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固