What's the best approach to store multiple images in database?
Upon browsing and searching for solution and approaches I found 2 options
first one is take the file name and concatenate and separate them using either comma or |
but I'm having doubts since I think that's messy and would produce errors later in the system
second is I make another table for images and add foreign key (post_id) to know which post it belongs.
Any suggestion will be appreciated.
CodePudding user response:
Both methods work well. I would place the second.
It can also provide convenience when using some image upload plugins (filepond, dropzone etc.).
If I were to choose the first method, I would save the serialized arrays (with serialize()
) for better bet.
CodePudding user response:
Second one because it is normalized and you can have a better DX with that, No weird implementation to edit or any manipulation of post.