Skip to content
niknetniko edited this page Mar 5, 2016 · 4 revisions

Getting started is simple. To quickly get started, you can create your menu within a middleware. Below you will find a sample middleware that you may use as a starting point.

Note: Don't forget to register this new middleware from within your app/Http/Kernel.php file.

<?php

namespace App\Http\Middleware;

use Closure;
use Menu;
use Caffeinated\Menus\Builder;

class MenuMiddleware
{
    /**
     * Run the request filter.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure                  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        Menu::make('example', function(Builder $menu) {
            $menu->add('Home', '/');
            $menu->add('About', '/about');
            $menu->add('Blog', '/blog');
            $menu->add('Contact Me', '/contact-me');
        });

        return $next($request);
    }
}

Note: Simply replace example with whatever you wish to call your menu.

Caffeinated Menus will automatically register your menu as a view composer (prepending your defined menu slug with menu_) that is accessible from all your views. Rendering your menu is simple from within your blade view files:

{!! $menu_example->asUl() !!}

The above will generate the following HTML:

<ul>
    <li><a href="http://yourwebsite.com">Home</a></li>
    <li><a href="http://yourwebsite.com/blog">Blog</a></li>
    <li><a href="http://yourwebsite.com/about">About</a></li>
    <li><a href="http://yourwebsite.com/contact">Contact</a></li>
</ul>

That's it as far as basic usage goes! Pretty simple, no? This is only the tip of the iceberg though, so be sure to go through the documentation here to learn about the more advanced uses (like creating your own Twitter Bootstrap menu)!

Clone this wiki locally