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

Cinek's avatar
Level 6

Chat's database structure

Hello, I have one problem with designing database structure for my app. I have 3 models: Events, groups and users. Relations: Events - Users - many to many Groups - Users - many to many

There will be available one chat withing group and one inside event. Additonally in the near future I am going to implement chats between two or more users.

i'm a bit confused what is the best way to design it. I created Chat model and many to many relation between chat and users.

1 idea: The members of group and event chats will be stored in respectively event_users and group_users tables. Only chats between users will be stored in chat_users.

Second idea: chat_users will be synchronized with event_users and group_users tables. The advantage of this way is that I will have simple separated logic to manage chats and there will be not many complicated queries to DB.

Thanks for any feedback or maybe other ideas

0 likes
0 replies

Please or to participate in this conversation.