I am passing a value in shared view by taking value from table. I need to know user ID for the purpose but Auth::check()
returns false. How do I do it? Below is code:
public function boot()
{
$basket_count = 0;
if (Auth::check()) { //always false
$loggedin_user_id = Auth::user()->id;
$basket_count = Cart::getBasketCount();
}
view()->share('basket_count', $basket_count);
}
OK turns out that
ServiceProviders
are not place for such things. The best thing is aMiddleware
. So if you want to call Auth, create middleware and pass value to views.You can use authentication directly in the controller file. Adding it in the middleware is a cleaner way of doing the authentication.
For eg. In CategoriesController.php
...
...
If you want to have a look at a complete example http://deepdivetuts.com/basic-create-edit-update-delete-functionality-laravel-5-3