Code Monkey home page Code Monkey logo

illuminate-menu's Introduction

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:

<ul>{!! Menu::items($items) !!}</ul>

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 <li> 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.

illuminate-menu's People

Contributors

lazychaser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

illuminate-menu's Issues

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

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.

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?

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.