Bit of a bad title, not quite sure how to research/describe what I'm trying to do.
有点糟糕的标题,不太确定如何研究/描述我正在尝试做什么。
I have a table called specifications with the fields
我有一个名为规格的表与字段
id, device_id, name, detail
Two rows for two different devices would for example be
例如,两个不同设备的两行
1, 1, weight, 300kg
2, 2, weight, 250kg
Now the way I need to display it is in a single table compare both devices, essentially like this:
现在我需要显示它的方式是在一个表中比较两个设备,基本上是这样的:
@foreach($specifications as $specification)
<tr>
<td>{{ $specification->name }}</td>
<td>{{ $specification->detailOne }}</td>
<td>{{ $specification->detailTwo }}</td>
</tr>
@endforeach
I'm having issues getting the right query or split the query in order to be able to go through the array like above. Anyone mind putting me on the right mindset? Do I query both specs and somehow resort it into an array I can use as above, or is there something else I should be looking at?
我在获取正确的查询或拆分查询时遇到问题,以便能够像上面那样通过数组。有人介意让我采取正确的心态吗?我是否查询这两个规格并以某种方式将其转换为我可以如上所述使用的数组,或者是否还有其他我应该关注的内容?
1 个解决方案
#1
0
This should work for you
这应该适合你
@foreach($specifications->groupBy('name') as $name => $specificationGrouped)
<tr>
<td>{{ $name }}</td>
@foreach($specificationGrouped as $specification)
<td>{{ $specification['detail'] }} ({{ $specification['device_id'] }})</td>
@endforeach
</tr>
@endforeach
#1
0
This should work for you
这应该适合你
@foreach($specifications->groupBy('name') as $name => $specificationGrouped)
<tr>
<td>{{ $name }}</td>
@foreach($specificationGrouped as $specification)
<td>{{ $specification['detail'] }} ({{ $specification['device_id'] }})</td>
@endforeach
</tr>
@endforeach