caffeinated / menus

:pushpin: Menu generator package for the Laravel framework
https://caffeinatedpackages.com
132 stars 59 forks source link

Filter #46

Closed mikhi closed 9 years ago

mikhi commented 9 years ago

Hi, Do you have any idea why in filter closure, dd(Auth::user()) returns null? I'm already logged in.

Thanks, and sorry for this rookie question!

kaidesu commented 9 years ago

No worries, this is an error on my part in the documentation. You should create your menu instance within a Middleware. Service Providers are loaded before the session is, so Auth will always return null in those instances.

soonkin commented 9 years ago

Hi, I'm facing the same issue, can you please clarify on how to create the menu within Middleware?

kaidesu commented 9 years ago
<?php

namespace App\Http\Middleware

use Closure;
use Menu;

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($menu) {
            $menu->add('Home', '/');
            $menu->add('About', '/about');
            $menu->add('Blog', '/blog');
            $menu->add('Contact Me', '/contact-me');
        });

        return $next($request);
    }
}

I've added this to the documentation here as well: https://github.com/caffeinated/menus/wiki/Basics-of-Menus

soonkin commented 9 years ago

Perfect, thank you so much!