我想在$items
数组中添加新元素,出于某些原因,我不想使用联接。
$items = DB::select(DB::raw('SELECT * FROM items WHERE items.id = '.$id.' ;'));
foreach($items as $item){
$product = DB::select(DB::raw(' select * from product
where product_id = '. $id.';' ));
$item->push($product);
}
我该怎么办?
根据Laravel文档,您似乎一切都正确,但是有错字
$item->push($product);
应该
$items->push($product);
我也想认为您正在寻找的实际方法是 put
$items->put('products', $product);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句