Closed mikhi closed 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.
Hi, I'm facing the same issue, can you please clarify on how to create the menu within Middleware?
<?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
Perfect, thank you so much!
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!