Display Table form with Eloquent Data Laravel

帅比萌擦擦* 提交于 2019-12-24 03:42:45

问题


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",},

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

回答1:


$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();


来源:https://stackoverflow.com/questions/31780016/display-table-form-with-eloquent-data-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!