Laravel分割收集方法

时间:2018-04-10 08:02:57

标签: php laravel eloquent

问题是如何将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> 

1 个答案:

答案 0 :(得分:1)

使用index获取特定的collections

@foreach($collections[0] as $collection) //here $collection is Collection 0