Download the PHP package hieu-le/laravel-menu without Composer

On this page you can find all versions of the php package hieu-le/laravel-menu. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-menu

Laravel Menu

Help to build menus easier in Laravel applications (currently support Laravel 5 only)

Build Status Latest Stable Version Code Climate Test Coverage Total Downloads License

Instalation

First, add this package to your project dependencies:

$> composer require "hieu-le/laravel-menu"

After Composer updated your vendors code, add the package service provider to your providers array in the config/app.php file:

HieuLe\LaravelMenu\LaravelMenuServiceProvider::class,

Now, you can access to the menu manager via app('menu.manager') object. If you want to use static methods via alias classes, register the package facade to your aliases array in the config/app.php file:

'Menu' => HieuLe\LaravelMenu\Facades\LaravelMenu::class,

Usage

You can create as many menus as you want in your application. A menu comes with a unique name which can be anything. You can get the menu instance via that name by menu method:

If there is no menu with the name you specified, a new one will be initiated and returned to you. Some menu comes with an optional header (or label), which can be set by the setLabel method on the menu instance.

The method return the menu instance itself to enable method chaining. Many menus can have the same label or don't have any label. Remember that you cannot retrieve a menu from menu manager via its label, you can only use its name.

I suggest two places to define your menus:

Add links to menu

API: $menu->addLink($text, array $url = [], $options = [])

If $url is an empty array, the href will be an hash character (#).

To assign an URL to the the link, pass a string to the to element of the $url array. Example: an item created with $url equals to ['to' => '/foo/bar'] has the href leading to http://your-domain.com/foo/bar, an item created with $url equals to ['to' => 'http://other-site.com/foo/bar'] has the href leading to http://other-site.com/foo/bar.

To assign an internal URL by your named route, pass the route name as string to the route element of the $url array. If the route has parameters, pass an array with the first element is the route name, the others are route parameters and the appropriate parameter name as key. For example:

To assign an internal URL by the action name, pass the action as string to the action element of the $url array. If the action has parameters, pass an array with the first element is the action, the others are the action parameter. For example:

If your desired link contains query string, you can pass an array to the query element of the $url array. I use http_build_query to create the query string and append it to the end of the URL created by the above options.

Add sub menu

API $menu->addSubMenu($menu, $options = [])

Options when create new menu item.

When creating new menu item (a link or a sub menu), you can pass an optional array as the $options parameter. The array can contain these elements:

Render the menu

I use Laravel built in view system to render the menu, so that you can easily customize the output of a menu. To get the HTML of a menu, call render method from the menu instance.

API: $menu->render($data = [], $view = '')

If you use the default built in view (the $view parameter is empty), there are 3 elements used in the $data array, all of them are strings:

Detect whether current menu item is active

In views, you usually want to add some active class to the menu items that currently selected. This package provides the isActive method from the menu manager to do that. You give a menu item and get a boolean value which tell you whether this menu item is currently active or not.

The isActive method check the is_active element of the current menu item first, if it is callable, the method return the result from that to you.

If there is no is_active element, the method use the url_def element as written above. The url_def element describe URLs that can make the current menu item active. Its value is an associative array:

See the documentation of Laravel Active package to get more detail.

Example with the default views

// routes.php
Route::get('/a', ['as' => 'links.a']);
Route::get('/a/new', ['as' => 'links.a.create']);
Route::get('/a/list', ['as' => 'links.a.list']);
Route::get('/a/{id}', ['as' => 'links.a.detail']);
Route::get('/b', ['as' => 'links.b']);
Route::get('/c', ['as' => 'links.c']);

// AppServiceProvider.php
public function boot() {
    $subMenu = app('menu.manager')->createMenu('Multilevel link A')
        ->addLink('Create A', ['route' => 'links.a.create'])
        ->addLink('Listing A', ['route' => ['links.a.list']]);

    $menu = app('menu.manager')->menu('sidebar')
        ->setLabel('Sidebar Navigation')
        ->addSubMenu($subMenu, ['id' => 'link-a', 'url_def' => ['route_pattern' => 'link.a.*']])
        ->addLink('Link C', ['route' => 'links.c']);

    // some thing else ...

    app('menu.manager')->menu('sidebar')
        // we want to insert link B before link C
        ->addLink('Link B', ['route' => 'links.b'], 'next_to' => 'link-a']);
}

// Some where in your view
{!! app('menu.manager')->menu('sidebar')->render() !!}

If you are visiting the URI /a/new, the HTML output will be:

<ul class="menu">
    <li class="header">
        Sidebar Navigation
    </li>
    <li class="menuitem active">
        <a href="#">
            Multilevel link A
        </a>
        <ul class="menu submenu">
            <li class="menuitem item">
                <a href="/a/new">Create A</a>
            </li>
            <li class="menuitem item">
                <a href="/a/list">Listing A</a>
            </li>
        </ul>
    </li>
    <li class="menuitem item">
        <a href="/b">Link B</a>
    </li>
    <li class="menuitem item">
        <a href="/c">Link C</a>
    </li>
</ul>

All versions of laravel-menu with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5.9
illuminate/view Version ^5.1
illuminate/routing Version ^5.1
illuminate/support Version ^5.1
hieu-le/active Version ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hieu-le/laravel-menu contains the following files

Loading the files please wait ....