I think you should handle that with roles instead,
- Admin has access to all
- district 1 has access to district 1
- district 2 has access to district 2
- and so on...
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
So I am working with a CRM project where user has some defined area which are break into smaller entities like state, district and block. They are in order states --> districts -- > blocks. One state can have many districts and one district can have many blocks also. I would like store them in 3 different tables say user_states, user_districts and user_blocks
scenario 1:
I am not going to store data in user_districts while user has full district access, same thing also applies for user_blocks while use has entire district access. In this scenario ORM sends wrong data specially data with wrong value while logged in user searching/filtering data from table. You may ask why I'm no savaing data in user_districts or user_blocks while user has full access to a state or district, the answer in one state may contains 20 district or 1 district may contain say 200 blocks. So row count will be huge and it'll increase as the user count go higher. System already runs with JSON colums to store the data but its has slower performance during query.
user 1 has all state access hence data will be available only in user_states
user 2 has specific state and district access hence data will be available only in user_states and user_districts
user 3 has all state access hence data will be available only in user_states
so if user 1 or user 2 is logged in they should be able to see user 3 in their query filter, unfortunately mySQL query skips user 3 as it does not contain any data in user_districts.
Please or to participate in this conversation.