Answer the question
In order to leave comments, you need to log in
Service providers in Laravel - how to know if a user is logged in?
I decided to connect the menu through the service provider, here is the code that I insert into the boot method:
if (\Auth::guest()) {
$links = '1';
} else {
$links = '2';
}
\Debugbar::info(\Auth::guest());
view()->composer('menu.menu', function($view) use ($links) {
$view->with('links', $links);
});
Answer the question
In order to leave comments, you need to log in
Replace with \Auth::user()
Then just like this:
dd($auth->user()); // null
view()->composer('partials.nav', function($view) use ($auth){
dd($auth->user()); // returns User object
$view->with('currentUser', $auth->user()); // does what you expect
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question