GithubHelp home page GithubHelp logo

frankpeters / laravel-sidebar Goto Github PK

View Code? Open in Web Editor NEW

This project forked from spartnernl/laravel-sidebar

0.0 1.0 0.0 113 KB

A Laravel Sidebar bulder

License: MIT License

XML 2.72% PHP 97.28%

laravel-sidebar's Introduction

Laravel Sidebar

Adding a menu

$builder = app('Maatwebsite\Sidebar\SidebarManager');

$builder->group('app', function ($group)
{
    $group->addItem('dashboard', function($item)
    {
        // Route method automatically transforms it into a route
        $item->route('acp.dashboard');

        // If you want to call route() yourself to pass optional parameters
        $item->route = route('acp.dashboard');
    });
}

Groups

It's possible to group the menu items. A little header will be rendered to separate the different menu items.

Adding items

The first parameter of $group->addItem() is the name. The name field will automatically be translated through the menu translation file. (e.g. menu.dashboard). If the translation does not exists, the given name will be displayed.

The second parameter is optionally a callback. Alternatively you can chain the methods.

You can change the route, name and icon. If you route given it will automatically be translated to acp.{$name}.index.

Item children

We can go a level deeper with the menu items by calling $item->addItem(). This will automatically nest them. You can add the same values to them as their parent item (including appends and badges).

Without group headings

To disable rendering of the group headings, you can easily use $builder->withoutGroup(). Group headings will now be ignored.

Appends

To append a quick link, you can use $item->append(). You can either pass the route or pass a callback:

// This will append a plus sign
$item->append('acp.pages.create');

// Chain methods
$item->append('acp.pages.custom')->icon('fa fa-pencil');

$item->append(function($append)
{
    $append->route('acp.pages.custom');
    $append->icon = 'fa fa-pencil';
});

You can add as many appends as you want!

Badges

To append a badge you can use $item->badge() You can either pass the value and color or pass a callback:

// This will add a quick badge with green color and the word new
$item->badge('new', 'badge-success');

// Chain methods
$item->badge('new')->color('badge-success');

// Inside the closure you can make use of dependency injection
$item->badge(function($append, PageRepository $repo)
{
    // Display a dynamic value
    $append->value = $repo->getCount();
});

Authorization

By default all groups, items, appends and badges are public for all users. You can use ->authorized(false) on all these objects to disable them or use any condition you want.

laravel-sidebar's People

Contributors

frankpeters avatar patrickbrouwers avatar

Watchers

 avatar

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.