There are no variables in a Collection; do you mean that each item in the Collection should get a new property? Or, do you want this additional data at the top-level (siblings of the Products)?
Jan 19, 2022
7
Level 1
Add data to the same collection without it appearing in the query
Hi, I have the next query
$products = collect();
$product = ProductFlat::leftJoin('product_images', 'product_flat.product_id', '=', 'product_images.product_id')
->select('product_flat.product_id as id','product_flat.name', 'product_flat.url_key as slug', 'product_images.path as image','product_flat.price')
->addSelect(DB::raw("0 as total"))
->addSelect(DB::raw("0 as quantity"))
->addSelect(DB::raw("'$inStock' as in_stock"))
->where('product_flat.name', $orderedProduct)->get();
$products->push($product);
And I would like to add two more variables to the collection
$totalQty = $productMain->getTypeInstance()->totalQuantity();
$stockStatus = $productMain->getTypeInstance()->checkStock();
How can I add the two variables for each product?
Please or to participate in this conversation.