Giter Site home page Giter Site logo

nguyendachuy / laravel-menu Goto Github PK

View Code? Open in Web Editor NEW

This project forked from harimayco/wmenu-builder

14.0 0.0 10.0 398 KB

Laravel Drag and Drop Dynamic Menu Generator (Bootstrap)

License: MIT License

JavaScript 11.69% CSS 9.14% PHP 50.16% Blade 29.02%
php laravel menu builder bootstrap drag-and-drop

laravel-menu's Introduction

Laravel Drag and Drop menu

Latest Stable Version Total Downloads Latest Unstable Version License

Laravel drag and drop menu

Installation

  1. Run
composer require nguyendachuy/laravel-menu
  1. Run publish
php artisan vendor:publish --provider="NguyenHuy\Menu\Providers\MenuServiceProvider"
  1. 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
  • CACHE ENABLED: Set this to true if you want to enable caching for menu items. Default is false.
  • CACHE KEY PREFIX: The prefix to use for cache keys. Default is 'menu'.
  • CACHE TTL: The time-to-live (in minutes) for cached menu items. Default is 60.
  1. Run migrate
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 NguyenHuy\Menu\Models\Menus;
use NguyenHuy\Menu\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','Test Menu')->first();

/* or get menu by name and the items with EAGER LOADING (RECOMENDED for better performance and less query call)*/
$menu = Menus::where('name','Test Menu')->with('items')->first();
/*or by id */
$menu = Menus::where('id', 1)->with('items')->first();

//you can access by model result
$public_menu = $menu->items;

//or you can convert it to array
$public_menu = $menu->items->toArray();
or Using helper
// 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
        @endif

        </ul><!-- /.menu -->
    </nav><!-- /#mainnav -->
 </div><!-- /.nav-wrap -->

HELPERS

Get Menu Items By Menu ID

use NguyenHuy\Menu\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 NguyenHuy\Menu\Facades\Menu;
...
/*
Parameter: Menu ID
Return: Array
*/
$menuList = Menu::getByName('Admin');

Customization

You can edit the menu interface in resources/views/vendor/nguyendachuy-menu/menu-html.blade.php

laravel-menu's People

Contributors

harimayco avatar nguyendachuy avatar lordmacu avatar developeroncall avatar monwolf avatar ezequiel9 avatar buzzclue avatar deep2065 avatar sadiqultra avatar lordmacus avatar nauvalazhar avatar konmavrakis avatar odhier avatar

Stargazers

dev.roony avatar Martin Frost avatar Harsh Arora avatar Amr Mostofa avatar Mohammad Salehi avatar  avatar Eqtada Bilhadi avatar Diskominsa Aceh Jaya avatar Baha Şener avatar Denis Hanif avatar Triopsi avatar Mathieu Leblond avatar Behnam Ahmadi avatar Yaroslav avatar

laravel-menu's Issues

Call to a member function connection() on null

I tried to include the library for my project using Laravel version 8.12 but I am getting an error.

Error
Call to a member function connection() on null

Illuminate\Database\Eloquent\Model::resolveConnection
vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1653

public static function resolveConnection($connection = null)

    {

        return static::$resolver->connection($connection);

    }

Package not install in laravel version 9. show that error

Your requirements could not be resolved to an installable set of packages.

Problem 1
- nguyendachuy/laravel-menu[2.1, ..., 2.1.1] require illuminate/support 5.* || 6.* || 7.* || 8.* -> found illuminate/support[v5.0.0, ..., v5.8.36, v6.0.0, ..., v6.20.44, v7.0.0, ..., v7.30.6, v8.0.0, ..., v8.83.27] but these were not loaded, likely because it conflicts with another require.
- Root composer.json requires nguyendachuy/laravel-menu ^2.1 -> satisfiable by nguyendachuy/laravel-menu[2.1, 2.1.1].

You can also try re-running composer require with an explicit version constraint, e.g. "composer require nguyendachuy/laravel-menu:*" to figure out if any version is installable, or "composer require nguyendachuy/laravel-menu:^2.1" if you know which you need.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Package not install in laravel version 10

project > composer require nguyendachuy/laravel-menu 1.0
The "1.0" constraint for "nguyendachuy/laravel-menu" appears too strict and will likely not match what you want. See https://getcomposer.org/constraints
./composer.json has been updated
Running composer update nguyendachuy/laravel-menu
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Root composer.json requires nguyendachuy/laravel-menu 1.0 -> satisfiable by nguyendachuy/laravel-menu[1.0].
- nguyendachuy/laravel-menu 1.0 requires illuminate/support 5.* || 6.* || 7.* || 8.* -> found illuminate/support[v5.0.0, ..., v5.8.36, v6.0.0, ..., v6.20.44, v7.0.0, ..., v7.30.6, v8.0.0, ..., v8.83.27] but these were not loaded, likely because it conflicts with another require.

Installation failed, reverting ./composer.json and ./composer.lock to their original content.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.