Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hussein_derbalah's avatar

belogs to many Relation between 3 tables

I have 3 entities Category,Post and Page. the relation between Category and Post is belongs to many ( and it works fine) and the relation between Page and Category is also belongs to many (it works fine too). now i want to retrieve all categories' posts in a page .Is there a way to make a directly relation between Page and Post? my tables structure :

categories: int id string title

posts: int id text content

categories_posts: int id int category_id int post_id

pages: int id string title

pages_categories: int id int page_id int category_id

0 likes
1 reply
UsmanBasharmal's avatar

Like you have created a pivot table for category and pages you can also create it for post and pages

Please or to participate in this conversation.