显示表与雄辩的数据Laravel [英] Display Table form with Eloquent Data Laravel
本文介绍了显示表与雄辩的数据Laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个以雄辩形式存储的对象结构
I have an Object structure that is store in Eloquent Form
{"item_id": "2",
"item_color": "Black",
"item_size": "L",
"item_Quantity": "5",},
{"item_id": "2",
"item_color": "Black",
"item_size": "M",
"item_Quantity": "5",},
{"item_id": "2",
"item_color": "Black",
"item_size": "S",
"item_Quantity": "5",},
{"item_id": "2",
"item_color": "White",
"item_size": "S",
"item_Quantity": "5",},
我要实现的是将具有相同 item_id 和 item_color 的所有item_quantity合并,并以这种形式显示在表格中.
What I'm trying to achieve is to combine up all item_quantity which has the same item_id and item_color and Display in Table form like this.
ItemID ItemColor ItemSize Quantity Total
2 Black L-M-S 5-5-5 15
2 White S 5 5
在我的研究中,这是最接近的解决方案,但是我无法以表格形式显示
In my research this is the nearest kind of solution but Im having trouble on displaying it in table form
http://stackoverflow.com/questions/23902541/add-array-values-of-same-array-keys-in-session
推荐答案
$items = DB::table('item')
->select(DB::raw("item_id,item_color,GROUP_CONCAT(item_size SEPARATOR '-') as ItemSize,GROUP_CONCAT(item_Quantity SEPARATOR '-') as Quantity,sum(item_Quantity) as TOTAL"))
->groupBy('item_id','item_color')
->get();
这篇关于显示表与雄辩的数据Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文