当数据达到 10 行时,如何将数据放在新列中

How to place data in a new column when it reaches 10 rows?

本文关键字:数据 新列中 行时      更新时间:2023-09-26

我在这里有这个html代码:

<div class="bids_container col-lg-8 col-lg-offset-2">
@each('comp.bid_summary', $bids, 'bid')
</div>

我的出价分页为 10。我在这里要做的是,当此列达到 10 行时,我想开始在其旁边的新列中添加新行。这可能以某种方式吗?

您可以

返回整个集合并chunk,而不是对出价进行分页,这将导致多个页面:

@foreach ($bids->chunk(10) as $chunk)
  <div class="row">
    @each('comp.bid_summary', $chunk, 'bid')
  </div>
@endforeach

$chunk是完整集合的子集

我喜欢

Tykus 的答案,但看起来 OP 没有在comp.bid_summary中定义列,所以我认为这样的事情更接近预期的结果:

<div class="bids_container">
  <div class="row">
    @foreach ($bids->chunk(10) as $chunk)
      <div class="col-lg-6">
        @each('comp.bid_summary', $chunk, 'bid')
      </div>
    @endforeach
 </div>
</div>

您可能希望按 20 分页以获得 2 列。

如果您删除分页并且结果超过 20 个,您将获得超过 2 列,因此您可以在分块之前->limit(20)以确保只显示 2 列。