darryldecode / laravelshoppingcart

Shopping Cart Implementation for Laravel Framework
1.32k stars 413 forks source link

How to get all carts for analysis #362

Open ZainabEid opened 1 year ago

ZainabEid commented 1 year ago

Hi I need to get all carts from database and view their details with conditions and item details ? when using eloquent model and get all carts pluck id to get the session id it returns a different number ! this is the logic I am trying to apply

public function getAll(){
 $all_carts_in_db =CartStorage::get();
  $carts=[];
   foreach ($all_carts_in_db as $cart_in_db ){
        $sessionKey=str_replace('_cart_items', '', $cart_in_db->id);
      $carts[]= Cart::session($sessionKey);
  }
return $carts;
}

the issue is the when I am trying to get the cart session key , $cart_in_db->id returns new number

the session Key I have entered is 51546e31-a956-4876-ab3d-33413d06d826-8g0W30LdUrk2hlte6zdbqCFMc6MyrmTM-c6daeb8549b1d1ce75ac4074d0ba305f

in database id is 51546e31-a956-4876-ab3d-33413d06d826-8g0W30LdUrk2hlte6zdbqCFMc6MyrmTM-c6daeb8549b1d1ce75ac4074d0ba305f_cart_items

the returned value from $cart_in_db->id is 9223372036854775807

I expected that $cart_in_db->id equals the id in the database