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

GodziLaravel's avatar

how to make a "properties" table more relational ?

Hello, I'm working on a Real estate project ,

Let's say there is 3 types in real estates (apartment, house and land)

actually I have one table property which is "not dynamic" because it's like :

----------------------------------------------
property
-----------------------------------------------
id
(...)
house_property_1
house_property_2
house_property_3
(...)
apartment_property_1
apartment_property_2
apartment_property_3
apartment_property_4
(...)
land_property_1
land_property_2
land_property_3
land_property_4
-----------------------------------------------

It seems not correct because these properties are not static.

I'm wondering how to extract 3 tables from the table above and how should be the relationship between them ?

Thanks

0 likes
3 replies
Snapey's avatar

You might be better referring to them as attributes because property (house/land/apartment) having property(attributes) will get a bit confusing.

Many ecommerce systems use something called an Entity Attribute Value (EAV) table - basically a table that can hold any type of attribute as a key:value store. Its a bit more work to setup, but gives you a more flexible architecture since you can hold anything in it.

Suppose for instance you decide that houses should record if they are brick or wood construction, and you don't have a column for that, then you have to alter the database design to add a 'construction' column, whereas with an EAV store, you would record property_id, 'construction','wood' for instance. New attributes may be added without necessarily having to alter the database design.

If you want to go with a more flat style, yet need to store different attributes per property type, then check this article of mine. If talks about how you might store different user profiles using a polymorphic relationship. The different profiles are the same as your house/apartment/land.

http://novate.co.uk/using-laravel-polymorphic-relationships-for-different-user-profiles/

automica's avatar

@snapey nice. I've come across the EAV model via magento. sounds like its a good fit here.

I'll give that article a look too. Always good to see get an experienced view on this subject.

Please or to participate in this conversation.