I'm not sure to understand what you need. But if you have to use same data in several tables, you should use a polymophic relationship.
https://laravel.com/docs/9.x/eloquent-relationships#polymorphic-relationships
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi there!
So I've been working on a project and its been alright so far, but now I feel like the data structure might need some improvements.
The way this should work:
Company contains company information, be it a name, brand color, established date and so on.
The user will be able to filter the Companies by color, industry, etc...
Every company, will have a Pages and Components. These will also have their own URL, that will get all company pages and display them - which then can be filtered by things like page name (which is what Page contains) but also by company color.
Now, I do also want to add independent pages, without companies. Would I then create a new table Pages and Components and rename the other ones to company_pages and company_components and then join them to show all of them? And when user wants to filter to see only page associated with company they can.
And the Pages then would also consist of everything that the company page has, color etc... since if I want to insert a page by its own, and give it a color, that wouldn't be possible unless its associated with a company.
So I feel like this data structure could be good:
company
- id
- color
- name
company_pages
- id
- company_id
- image
company_components
- company_id
general_pages
- id
- color
- name
- image
And same for components
And then join these two tables when displaying the data and that way if the user wants to filter by color, they all can be filtered.
What do you guys think? Or is this a wrong way to look at this? Because I don't see a reason to make all pages to have color since its going to be exactly the same as the company has so it would be a massive 1000 duplicate records for each company. So just the company should have the color I'm sure. But then those pages that aren't associated with the company, have their own table.
I suppose if I do it like that I need to make sure it can be displayed in one component as well.
So far this is what I got https://i.imgur.com/OOpqta6.png but I feel like this sint' flexible enough and naming could be possibly improved.
Please or to participate in this conversation.