My opinion is that it's often better to user multiple tables than an array in a text column. But it depends on your needs : if you don't do any search, any ordering, ... on the data, you can simply store them in an array. If you need to do some search, ordering, ... it's much better to store them in another table.
Multiple MySQL tables or one table with everything stored as array in text column
Hi there,
I'm building a page builder. In this page builder, a Page.php can have many PageSections. Each of these page sections has it's own fields like title, subtitle, featured image, video, etc.
I have two choices here:
-
Polymorph relationship (
$page->pageSections->first()->sectionable). Each section is a model, so we need a table in the database. We can add the title and everything in its own database column, add relationships like images with Spatie Medialibrary, easier search, etc. -
Store information as an array in
PageSectionand use Data Transfer Object to read and write information.
I haven't been in this situation before, so I'm not sure if the complexity of maintaining a model/table for each page section is worth the benefits. Or a simple text column in the page section would work just fine.
Any tips from someone who has been in this situation? Am I missing something?
Thanks!
Please or to participate in this conversation.