所以我有以下查询:
$sections = Section::with(['subsections.tasks.companies'])
->where('parent', NULL)
->sorted()
->get()
->toArray();
这将返回以下类型的结构:
array:2 [▼
0 => array:10 [▼
"id" => 12
"name" => "Chapter 1"
"parent" => null
"position" => 12
"created_at" => "2018-05-10 16:43:04"
"updated_at" => "2018-06-08 14:37:54"
"completed" => false
"subsections" => array:2 [▼
0 => array:10 [▼
"id" => 14
"name" => "Subcatgeory 2"
"parent" => 12
"created_at" => "2018-05-10 16:52:28"
"updated_at" => "2018-06-08 14:37:51"
"completed" => false
"tasks" => array:1 [▼
0 => array:15 [▼
"id" => 3
"name" => "Another task"
"active" => 1
"created_at" => "2018-05-10 16:52:50"
"updated_at" => "2018-05-14 09:33:32"
"pivot" => array:2 [▶]
"companies" => []
]
]
]
1 => array:10 [▶]
]
]
1 => array:10 [▶]
]
基本上是“部分”>“子部分”>“任务”。
然后我尝试将这些数据导出到html表中,但是我想按如下所示的任务节对数据进行分组:
stage1是外部父节的名称。
我设法在视图文件中打印出父节:
<table class="table table-bordered">
<tbody>
<tr>
<td>Customer</td>
@foreach($sections as $section)
<td>{{ $section->name }}</td>
@endforeach
</tr>
<tr>
<th></th>
<th>Task 1</th>
<th>Task 2</th>
<th>Task 3</th>
<th>Task 4</th>
</tr>
<tbody>
<tr>
<td></td>
<td>Date time</td>
<td>Date time</td>
<td>Date time</td>
<td>Date time</td>
</tr>
</tbody>
</table>
但是我要通过按上述屏幕快照中的任务进行分组来打印数据,因为我必须停留在主循环中,但必须突破<tr>
标记。谁能帮助我实现这一目标?