Answer the question
In order to leave comments, you need to log in
How to make a selection in a controller using pivot?
There is a table posts
id
post
----
post_categories
id
Category
---
pivot post_post_category
post_id
post_category_id
Everything works - creating, editing, deleting through models. I can not achieve a selection by post_category_id. I copied and pasted this request:
Post::with(['postCategories' => function($query) {
$query->wherePivot('post_category_id',$this->page);
}])->get();
Answer the question
In order to leave comments, you need to log in
Normal heroes always go around:
Post::with('postCategories')->whereHas('postCategories', function($q) {
$q->where('post_category_id','=',$this->page);
})
->orderBy('created_at', 'desc')
->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question