Level 102
What you have there is called a many to many relationship, and the question_tags is the pivot table:
https://laravel.com/docs/9.x/eloquent-relationships#many-to-many
So both relationships are belongsToMany()
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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 ?
What you have there is called a many to many relationship, and the question_tags is the pivot table:
https://laravel.com/docs/9.x/eloquent-relationships#many-to-many
So both relationships are belongsToMany()
Please or to participate in this conversation.