Adgower
1 week ago

Many to Many Polymorphic

Posted 1 week ago by Adgower

I have the following: Events are schedulable and can have courses OR services. This works fine I can attach multiple courses OR services per event, but if the event is for a course then there is actually only ever 1 course. So instead of return a collection how can I either save just 1 course or have it return without having to:

$event->courses->first()->name;

rather

$event->course->name;

Also thought about also putting another morph directly on the event table, but then this over complicates the goal. I think...

If you have tips to point me in the right direction I would appreciate it. I'm not entirely sure about the best way to go about this.

Thanks

Please sign in or create an account to participate in this conversation.