So I am usually getting the current user using Auth::user()
and when I am determining if a user is actually logged in Auth::check
. However this doesn't seem to work in my AppServiceProvider
. I am using it to share data across all views. I var_dump
both Auth::user()
and Auth::check()
while logged in and I get NULL
and false
.
How can I get the current user inside my AppServiceProvider
? If that isn't possible, what is the way to get data that is unique for each user (data that is different according to the user_id
) across all views. Here is my code for clarification.
if (Auth::check()) {
$cart = Cart::where('user_id', Auth::user()->id);
if ($cart) {
view()->share('cart', $cart);
}
} else {
view()->share('cartItems', Session::get('items'));
}