问题是如何将collection
打印到视图中。并且第一个div只打印Collection 0
而下一个Collection ++
就像这样
ExamsController @创建
$collections = $questions->split(5);
$collections->toArray();
dd($collections);
DD($集合);
Collection {#455 ▼
#items: array:5 [▼
0 => Collection {#394 ▶}
1 => Collection {#619 ▶}
2 => Collection {#407 ▶}
3 => Collection {#398 ▶}
4 => Collection {#275 ▶}
]
}
Create.blade.php
<div>@foreach($collections as $collection)
收集0
@endforeach</div>
<div>@foreach($collections as $collection)
Collection 1
@endforeach</div>
<div>@foreach($collections as $collection)
收集2
@endforeach</div>
<div>@foreach($collections as $collection)
收集3
@endforeach</div>
<div>@foreach($collections as $collection)
收集4
@endforeach</div>
答案 0 :(得分:1)
使用index
获取特定的collections
@foreach($collections[0] as $collection) //here $collection is Collection 0