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

speedydan's avatar

Advice on project structure

Hi there!

So, I'm working on a project that requires a bit of complex functionality - however, what I'm hesitating on is how to store user profile data.

At the moment, I have a standard user table which records all info from the registration form, and email and password so they can obviously log in.

Each user is going to have quite an in-depth profile - it's split into 8 different sections, and I'd say probably around 60 fields or so. My question is what would be the best way to store this data in the db? I appreciate there may not be a right or wrong way - just interested to hear approaches. I'd figured that I'd create a Profile model which would belong to a user, then just store all the data in a single table?

0 likes
2 replies
cmdobueno's avatar

I guess in part it comes down to the information.

Here is a quick example.

I have a user, and I store the very basic information in the users table (name, password, email... those normalized items)

My user additionally also have contact information. This I have created a polymorphic relationship called contactable. (additionally there is a contact type which could be something like primary, or emergency... this will make sense in a few minutes).

So to go with the contactable trait, I have a user able to have several emergency contacts, as well the ability to track their previous addresses.

Additionally I have avatars, which i tend to store in their own table

I have found that a modular approach (properly balanced, no 1-2 field tables) helps. That way, I am pulling less data when I need less data. You can control some of this with ->get(['column','names']) but this tends to be hard to do on releations.

For your structure, if it makes sense, I might break down those sections into tables. IT could help.

1 like
martinbean's avatar

@speedydan It depends on the fields, really. If they’re likely to change, then you may consider modelling each profile question as an entity (i.e. a ProfileQuestion model), and a user’s profile being made up of ProfileAnswer models that’s a pivot between the question and user, with an additional column to hold the user’s answer.

1 like

Please or to participate in this conversation.