将同一类别类型的项目分组
我有此方法返回所提供的服务
public function order_services(){
$services = DB::select('select * from services');
return view('guests/services',['services'=>$services]);;
}
,并且我像这样显示
<ul class="list-group" id="myUl">
@foreach ($services as $service)
<li class="list-group-item d-flex justify-content-between align-items-center border border-danger"><span style="font-size:24px; color:red
"><i class="bi bi-check-circle font-weight-bold "></i></span> <span style="font-weight:bold" id="service_category">{{ $service->service_category }}</span><span><u><i class="bi bi-magic"></i></u></span></li>
<li class="list-group-item d-flex justify-content-between align-items-center"><span class="product_name" style="font-size:24px; color:#870FD1" data-price="349.34"><i class="bi bi-plus-circle"></i></span> <span class="product_name" id="service_name" data-price="{{ $service->service_price }}" data-category="{{ $service->service_category }}" >{{ $service->service_name }}</span><span class="text-success"><u>Available</u></span></li>
@endforeach
</ul>
我的表具有service_name
and service_category
我想显示service> servication_category
as标题和该类别下的所有服务。这可以在刀片中完成,还是需要首先格式化控制器中的结果?
I have this method that returns the services being offered
public function order_services(){
$services = DB::select('select * from services');
return view('guests/services',['services'=>$services]);;
}
and i am displaying like this
<ul class="list-group" id="myUl">
@foreach ($services as $service)
<li class="list-group-item d-flex justify-content-between align-items-center border border-danger"><span style="font-size:24px; color:red
"><i class="bi bi-check-circle font-weight-bold "></i></span> <span style="font-weight:bold" id="service_category">{{ $service->service_category }}</span><span><u><i class="bi bi-magic"></i></u></span></li>
<li class="list-group-item d-flex justify-content-between align-items-center"><span class="product_name" style="font-size:24px; color:#870FD1" data-price="349.34"><i class="bi bi-plus-circle"></i></span> <span class="product_name" id="service_name" data-price="{{ $service->service_price }}" data-category="{{ $service->service_category }}" >{{ $service->service_name }}</span><span class="text-success"><u>Available</u></span></li>
@endforeach
</ul>
My table has service_name
and service_category
I would like to display service_category
as header and all the services under that category. Can this be done within blade or do i need to format the results in my controller first?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将列表与php(在Blade的控制器中为@PHP指令)分组:
更新的方法
,您可以在Blade中使用$ list以显示结果:
You can grouping the list with php (in controller of blade into @php directive):
Updated method
And you can use $list in blade for display the result: