![](/img/trans.png)
[英]Get conferences when “All Categories” is clicked independently of the conference category
[英]Order the categories by the number of conferences associated with each category
我得到所有類別,如:
public function index(){
return view('home')
->with('categories', Category::orderBy('created_at', 'desc')->get())
->with('conferences', Conference::orderBy('created_at','desc')->where('status','P')->take(8)->get())
}
然后在刀片文件中,顯示如下類別。 但是您知道如何通過與每個類別關聯的會議數量來排序類別嗎? 即,首先顯示與更多會議相關聯的類別。 您知道如何實現嗎?
<div class=" d-md-block">
<div class="container">
<div class="row">
<div class="col p-0 m-0">
<ul class="Categories__Menu">
@foreach($categories->take(6) as $category)
<li class="">
<a href="javascript:void(0)" name="category" id="{{$category->id}}">{{$category->name}}</a>
</li>
@endforeach
<li><a data-toggle="modal" id="showCategories" data-target=".bd-example-modal-lg" href="">More <i class="fa fa-caret-down" aria-hidden="true"></i></a></li>
</ul>
</div>
</div>
</div>
</div>
用這個。
Category::withCount('conferences')->orderBy('conferences_count', 'desc')->get();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.