How to display data by category?

Hello. There are three tables(with posts with categories and free) Post can have multiple categories and a category can have multiple posts(it turns out many-to-many). How to display posts in a specific category? About ORM read a lot of documentation(about the relationship), I can't still understand how and what. I would like to know more about the withdrawal of posts for a given category, the relationship I have configured correctly. Can not realize the output when you select a category. Thank you.
July 2nd 19 at 18:11
1 answer
July 2nd 19 at 18:13
Solution
If I understand correctly, something like this
$category_id = 10; // for example for category with id 10
$category = Category::find($category_id);

$posts = $category->posts(); // get all posts of category 10

return view('posts')->with(['posts' => $posts]); // pass in vushku posts

Find more questions by tags Laravel