我总共有4个使用Laravel的表单数据库,我想将其分开 每行将有2个项目,意味着顶部2个和底部2个
这是我的代码:
@extends('layouts/app')
@section('content')
<h1>Clubs & Societies</h1>
<p>This is Clubs And Societies</p>
<h2>Categories</h2>
@if (count($categories)>0)
@foreach ($categories as $category)
<div class="container col-md-3">
<div class="card card-body bg-light row-fluid" style="display:flex">
{{$category->category_name}}
</div>
</div>
@endforeach
@else
<p>No Category Found</p>
@endif
@endsection
答案 0 :(得分:2)
您可以使用chunk()方法将$categories
拆分为每个集合有02个项目的集合。
https://laravel.com/docs/5.8/collections#method-chunk
$categories = $categories->chunk(2);
现在,您可以遍历顶部的$categories->first()
和底部的$categories->last()
。