0

I created a method in my controller of laravel and want to access userid from session

static function cartItem()
{
    $userId=Session::get('cart')['id'];
    return Cart::where('user_id', $id)->count();
}

but I am getting this error "Trying to access array offset on value of type null" and I don't know why can anyone help me in this

  • use `auth()->id`. Cz session is unique – Abdulla Nilam Sep 06 '22 at 09:07
  • I made changes to my code according to your suggestion static function cartItem() { $userId=auth()->id; return Cart::where('user_id', $userId)->count(); } but now I am getting this error "Undefined property: Illuminate\Auth\AuthManager::$id" – Pankaj Mehta Sep 06 '22 at 10:09

0 Answers0