ethar
1 month ago

query inside foreach

Posted 1 month ago by ethar

i try to get all product where id in array

 if(isset($_COOKIE["shopping_cart_panorama"])){
   $cookie_data = stripslashes($_COOKIE["shopping_cart_panorama"]);
   $cart_data=json_decode($cookie_data,true);
   $products=[];
   foreach ($cart_data as $key=>$values){
       $products=Products::select('id','img','slug_'.getLange().' as slug','name_'.getLange().' as productName','price')
                    ->where('active',1)
                    ->where('id',$values['item_id'])
                    ->take(5)
                    ->get();
            }
  return $products;
        }

but its return just first result (id)

Please sign in or create an account to participate in this conversation.