ChrisPercival's avatar

Take two -> Joining a group of to their related records

Hi All

Sorry to ask again, but I probably did not make myself clear in the first instance.

The scenario…

I have Posts, Users & Categories.

Posts have a many to many relationship with Categories via a pivot table category_
Post & Users also has a many to many relationship with Categories via a pivot table category_user.

What needs to happen…

A user chooses, from the list of Categories (say A, B, C, D, & E), the categories B & D, for example.

Posts have one or many Categories.  I need to show, in a list, all the Posts with the B & D Categories with pagination.

Currently I am using the code below to get the Posts from one category, can someone please help.

Thanks in advance

Chris

public function index(Category $category)
{
        $posts = $category->posts()->where('published', '=', 2)->paginate(20);
    return view(‘posts.index', compact('posts'));
}
0 likes
1 reply

Please or to participate in this conversation.