Courses

How to Structure Databases in Laravel

Rare Cases of HasOne Relationship

avatar

Hi Povilas, i have a scenario with two tables, each table has around 60 colums. Those two tables share the same 50 columns. So i thought to group the 50 columns in 5 or 6 different tables with One-2-One Polymorphic relationship on the main table. My question is how do i structure the store method in the controller as you have first to create the main table and then the other table by as $originalTable->secondTable()->create([....]);. So how do i create the third, and forth table? Or should i structure my database in a complete different way? Hope you understand the way i explained it. Thank you in advance.

avatar

Hi Vilior, such questions about the relationships are almost impossible to answer without actually trying it out and playing around with the structure whether it fits. So unfortunately I can't answer in a quick comment here.

avatar

Thank you for your answer. That makes completely sense.