问题是如何将收藏夹打印到视图中.并且第一个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)
集合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>
解决方法:
使用索引获取特定集合
@foreach($collections[0] as $collection) //here $collection is Collection 0