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

ShaunL's avatar

Polymorphic relationships

Hi all,

need some feedback on a project i'm about to spin up here. I'm trying to create a quiz system, however, I find i'm needing some help with eloquent models. The quiz system will consist of several Challenges and I want the actual challenge types to be different. For example I would have a drag and drop type then maybe a standard multiple choice quiz type. So I would have to relate two models to a parent. Would this be a use case for polymorphic relationships? And if so, it seems like this is somewhat of an inverse scenario from the documentation? The children models to a Challenge will have different methods and potentially different relationships to other models, would that be a red flag? I'm just not sure how to map this type of application out as i've never used polymorphic stuff before.

0 likes
1 reply
jlrdw's avatar

As long as same types are used Polymorphic Relations should work, but you may have to write some custom stuff with query builder, hard to say. Watch a video on Polymorphic Relations then decide. Don't be afraid to write some custom queries if need be. Taylor provided many techniques for data retrieval. Give something a try, and once stuck, show code and ask.

1 like

Please or to participate in this conversation.