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

Gabotronix's avatar

Review Model relationship with multiple tables?

Hi everybody, My app has many models, particularly any logged in user can give feedback and create a review, they can create a plain Review, a DiscountReview and PostReview, this three models are my review models. One DiscountReview belongs to a Discount, one Discount can have many DiscountReviews ... so after some time I just noticed that since a review will always have the same attributes (title, body, rating ... ) maybe I should write a single Review Model and attach it to other Models, a Post, a Discount and other Models can have a Review associated to them or not.

So my question is how can I set up a relationship like this with laravel?

0 likes
1 reply
mstrauss's avatar

Hi @gabotronix

It sounds like you might be after a polymorphic relationship, see more about it here in the docs: https://laravel.com/docs/master/eloquent-relationships#polymorphic-relationships

Or checkout the video on Laracasts about the subject: https://laracasts.com/series/eloquent-relationships/episodes/5

While the name sounds intimidating, it's really not that bad, especially when you have a something to actually apply it to and it's not all abstract.

Please or to participate in this conversation.