I have following code:
In a Category Model
public function posts()
{
return $this->belongsToMany(Post::class, 'post__post_category_relations', 'category_id');
}
public function children()
{
return $this->hasMany(Category::class, 'parent_id');
}
In a Category Controller:
public function index(Category $category){
$category_childrens = $category->children;
$posts = ???;
return view('show.posts',compact('posts'));
}
I am trying to retrieve the $posts
associated with $category_childrens
and pass them to my view.