A TWBS menu builder for Laravel

Overview

Laravel Menu Builder

A menu builder for Laravel 4-5 using Bootstrap's markup.

Build Status Latest Stable Version Total Downloads

Документация на Русском

Note that this package is shipped with no styles nor scripts, you have to download them manually from Twitter Bootstrap's site.

Installation

Install using Composer:

composer require kalnoy/illuminate-menu:~1.0

Add a service provider:

'providers' => [
    'Illuminate\Html\MenuServiceProvider',
],

And a facade:

'aliases' => [
    'Menu' => 'Illuminate\Support\Facades\Menu',
],

Documentation

Rendering a menu:

{!! Menu::render($items, $attributes) !!}

Where $attributes is optional array of html attributes for ul element.

Rendering a list of menu items:

  
    {!! Menu::items($items) !!}

Rendering a single menu item:

{!! Menu::item($label, $url) !!}
{!! Menu::item($label, $options) !!}
{!! Menu::item($options) !!}

See a list of available options below.

Basic example:

Menu::render([
    'Link to url' => 'bar',
    'Link to external url' => 'http://bar',
    [ 'label' => 'Link to url', 'url' => 'bar' ],
    'Link to route' => [ 'route' => [ 'route.name', 'foo' => 'bar' ] ],
]);

Rendering an item with a drop down menu:

{!! Menu::item([
    'label' => 'Settings',
    'icon' => 'wrench',
    'items' => [
        'Foo' => 'bar',
        '-', // divider
        'Logout' => [ 'route' => 'logout_path' ],
    ],
]) !!}

Controlling whether the item is visible:

{!! Menu::item([
    'label' => 'Foo',
    'url' => 'bar',
    'visible' => function () { return Config::get('app.debug'); },
] !!}

Item options

You can specify an array of following options:

  • label is a label of the item, automatically translated, so you can specify lang string id
  • url is the url which can be a full URI or local path
  • route to specify a route, possibly with parameters
  • secure; specify true to make url be secure (doesn't affect route option)
  • items is an array of items for drop down menu
  • linkOptions is an array of additional link attributes

Changing the state of the item:

  • visible is a boolean value or closure to specify whether the item is visible
  • active is a boolean value or closure to specify whether to add active class to item; if not specified, determined automatically based on current url
  • disabled is a boolean value or closure to specify whether the menu item is disabled

Presentation options:

  • icon is a glyphicon id, i.e. pencil
  • badge is a value for badge (scalar or closure)
  • and any other parameter that will be rendered as an attribute for
  • element.

Customization

Though this menu builder intended to be used together with bootstrap markup, you can customize it however you like by extending Illuminate\Html\MenuBuilder class and overriding base methods.

You might also like...
Laravel Mysql Spatial Builder Extension

magutti-spatial V2 Laravel Builder Mysql Spatial Extension Laravel Builder extensions to calculate distances between two Spatial points using Mysql na

A simple to use query builder for the jQuery QueryBuilder plugin for use with Laravel.
A simple to use query builder for the jQuery QueryBuilder plugin for use with Laravel.

QueryBuilderParser Status Label Status Value Build Insights Code Climate Test Coverage QueryBuilderParser is designed mainly to be used inside Laravel

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)

Laravel MongoDB This package adds functionalities to the Eloquent model and Query builder for MongoDB, using the original Laravel API. This library ex

A powerful form builder, for Laravel and other frameworks (stand-alone too)

Former A Laravelish way to create and format forms Former outputs form elements in HTML compatible with your favorite CSS framework (Bootstrap and Fou

Laravel API architecture builder based on artisan commands.

🧑‍🔬 API-Formula Laravel API architecture builder based on artisan commands. This package provides a nice and fluent way to generate combined control

A Laravel Admin Starter project with Page Builder, Roles, Impersonation, Analytics, Blog, News, Banners, FAQ, Testimonials and more

Laravel CMS Starter Project A Laravel CMS Starter project with AdminLTE theme and core features. Preview project here User: [email protected]

Builder - A handful of tools for Rapid Laravel Development

Grafite Builder Grafite has archived this project and no longer supports or develops the code. We recommend using only as a source of ideas for your o

A DynamoDB based Eloquent model and Query builder for Laravel.

Laravel DynamoDB A DynamoDB based Eloquent model and Query builder for Laravel. You can find an example implementation in kitar/simplechat. Motivation

Generate and autoload custom Helpers, Builder Scope, Service class, Trait

laravel-make-extender Generate and autoload custom helpers, It can generate multilevel helpers in the context of the directory. Generate Service class

Comments
  • ability to ajax

    ability to ajax

    also, what about the ability to ajax; if one uses an ajax syntax as url using

    $menuitems = $Items->map(function ($item) use ($urlroot) { return [ 'label' => $item->name, 'url' => "javascript: $.get('".$urlroot."/".$item->id."', function(data){ $('#form-placeholder').html(data);});", 'secure' => true ]; })->all();

    you end up with <a href="https://project.local/javascript: $.get('reports/8', function(data){ $('#form-placeholder').html(data);});">Product:Criteria matrix</a>

    instead of <a href="javascript: $.get('https://project.local/reports/8', function(data){ $('#form-placeholder').html(data);});">Product:Criteria matrix</a>

    should I be using some other method/syntax?

    opened by harrisoftware 12
  • any more examples

    any more examples

    Hi I want to use this package. Do you have any examples of how to practically use this - like how to turn a returned collection into a menu for example?

    $menuitems = array(); $Themes = Themes::all(); foreach ($Themes as $theme) { $menuitems[]= [ 'label' => $theme->label, 'url' => $theme->url ]; }

    Menu::render($menuitems);

    Is this anywhere close?

    or is it as simple as

    Menu::render($Themes);

    if there are label and url fields in the returned collection.

    opened by harrisoftware 7
  • using target=_blank

    using target=_blank

    this is working well for me, but I'd like to be able to specify opening the url in a new window (via target=_blank) or some other switch like you have for 'secure'. Is this already available and I just don't know how to do it? thanks in advance

    enhancement 
    opened by harrisoftware 4
  • url redirect from menu seems hardcoded to http only

    url redirect from menu seems hardcoded to http only

            foreach ($Items as $item) {
                $menuitems[] = [ 'label' => $item->name, 'url' => $url.'/'.$item->id ];
            }
    

    the route served over https://server.local/ when these menu items are rendered, the URL reverts to http://server.local/$url

    is that hardcoded??

    opened by harrisoftware 3
Owner
Alexander Kalnoy
Alexander Kalnoy
Html menu generator for Laravel

Html Menu Generator for Laravel This is the Laravel version of our menu package adds some extras like convenience methods for generating URLs and macr

Spatie 813 Jan 4, 2023
📝 Artisan Menu - Use Artisan via an elegant console GUI

?? Artisan Menu Use Artisan via an elegant console GUI Features Run built-in and custom Artisan commands from a console GUI Prompts to enter required

Jordan Hall 149 Dec 29, 2022
Menu Library for PHP

KnpMenu The KnpMenu library provides object oriented menus for PHP. It is used by the KnpMenuBundle for Symfony but can now be used stand-alone. Insta

KNP Labs 1.3k Jan 1, 2023
MUP - Menu Up

MUP (aka: 'Menu Up') What is it? It's a bash script that generates a selection menu from a simple configuration file. Config: [Cache: Flush && Clean]

Nathan 9 Aug 19, 2020
📝 Artisan Menu - Use Artisan via an elegant console GUI

?? Artisan Menu Use Artisan via an elegant console GUI Features Run built-in and custom Artisan commands from a console GUI Prompts to enter required

Jordan Hall 148 Nov 29, 2022
This tool gives you the ability to set the default collapse state for Nova 4.0 menu items.

Nova Menu Collapsed This tool gives you the ability to set the default collapse state for Nova 4.0 menu items. Requirements php: >=8.0 laravel/nova: ^

Artem Stepanenko 10 Nov 17, 2022
Plugin for Filament Admin that adds a dropdown menu to the header to quickly create new items.

Filament Quick Create Plugin for Filament Admin that adds a dropdown menu to the header to quickly create new items from any page. Installation Instal

Adam Weston 45 Dec 27, 2022
Laravel Form builder for version 5+!

Laravel 5 form builder Form builder for Laravel 5 inspired by Symfony's form builder. With help of Laravels FormBuilder class creates forms that can b

Kristijan Husak 1.7k Dec 31, 2022
Provides a Eloquent query builder for Laravel or Lumen

This package provides an advanced filter for Laravel or Lumen model based on incoming requets.

M.Fouladgar 484 Jan 4, 2023
Reactive Form Builder for Vue.js with Laravel Support

Dynamic Form Builder for Laravel with Vue.js Create even the most complex forms with ease, using two-sided validation, eloquent, nested elements, cond

Laraform 340 Dec 31, 2022