【问题标题】:Laravel split collection methodLaravel 拆分收集方法
【发布时间】:2018-04-10 08:02:56
【问题描述】:

问题是我如何将collections 打印到视图中。第一个 div 只打印 Collection 0 和下一个 Collection ++ 像这样

ExamsController@create

$collections = $questions->split(5);
$collections->toArray();
dd($collections);

dd($collections);

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> 

【问题讨论】:

  • 好的,请问有什么问题?
  • 是的,我忘记了。正在写对不起。现在请检查一下

标签: php laravel eloquent


【解决方案1】:

使用index 获取特定的collections

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

【讨论】:

    猜你喜欢
    • 2017-10-26
    • 2019-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    相关资源
    最近更新 更多