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

vinod@snayvik.com's avatar

Relation between connected models

I have 3 tables : questions, tags, question_tags. questions and tags have normal entries but in question_tags we have question_id and tag_id columns. Each question can have multiple tags. I want to fetch questions with tags using eloquent queries like

Question::with('tags')->paginate(12);

How i can add relation in models like hasMany and belongsTo ?

0 likes
1 reply

Please or to participate in this conversation.