Laravel version 7.0, MySQL version 5.8
I am going to design database for livechat system. Here are related models & tables.
User model - users table (id, name, email, address..)
Guest model - guests table (id, name, ipAddress)
Team model - teams table (id, name, image)
team_has_users (id, team_id, user_id)
User should be able to send messages to User, Team, Guest.
Here are the possible cases that I could think.
- first approach
messsages table (id, content, from_id, to_id, from_model, to_model) // I think this is insufficient to save read_status for each users.
- second approach
messages table (id, content)
message_from_to table (id, message_id, from_id, to_id, read_status)
from_id will be id of either users table or guests table.
But to_id and read status is a bit tricky for me.
Can anyone help me?
Thank you