Answer the question
In order to leave comments, you need to log in
How to make a filter in Laravel?
I have a collection of buildings and posts associated with these buildings are attached with them. Posts have a variety of "News => 2" and "Promotions => 1" how to filter correctly.
With this method I get all the buildings
public function stocksIndex() {
return view('posts.index', [
'page' => Page::whereRoute('stocks.index')->first(),
'buildings' => Building::showInPosts()->get()
]);
}
@foreach ($building->posts as $post)
<div class="grid__col-4 grid__col_md_6 grid__col_sm_1 mb-2">
@include('posts.card', ['post' => $post])
</div>
@endforeach
"category_id" => 1
public function stocksIndex() {
return view('posts.index', [
'page' => Page::whereRoute('stocks.index')->first(),
'buildings' => Building::showInPosts()->whereHas('posts', function($stocks) {
$stocks->where('category_id', 1);
})->get()
]);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question