Design DB for chats between users - laravel

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.
First 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.

I believe that Chat has a polymorphic association with Group and Event (and maybe User as well). Some solutions to the problem are provided here:
https://www.slideshare.net/billkarwin/practical-object-oriented-models-in-sql/29-Polymorphic_Assocations_Solutions_Exclusive_arcs
Could something like this work?
ChatUser
id
user_id
chat_id
Chat (exclusive arcs method)
id
event_id (nullable)
group_id (nullable)
description/etc
ChatMessage
id
chat_id
user_id_from
user_id_to (nullable)
date
message
Assumptions made:
event/group can contain multiple chats
user can belong to a group but not to group chat
Besides, Laravel comes with a native polymorphic relation handling solution. It could fit here as well.

User can participate to an event and event can have many users who participate to that event, in this specific case we need to use as Many to Many relation Laravel One to Many Relation
event_user
id
event_id
user_id
User can be member of many group and a group can avec many member, in this case we need a Many to Many relation Laravel Many to Many Relation
group_user
id
group_id
user_id
chat can be related to an event or a group, so we save the type of the chat witch can be either Event or Group and the corresponding ID of that event or group. so if we have a particular chat we can retreive all users related to that chat through the corresponding event or group it depending of the chatable_type in each case, to learn more see Laravel Many To Many Polymorphic Relations
chats
id
name
chatable_id
chatable_type
we need also one table to save all conversations for specific chat
messages
id
chat_id
message
created_at
and for users chat you can create a separate table witch can save the related information about that chat specifiquely
conversations
id
sender_id
receiver_id
message
all sender_id and receiver_id will be foreign key witch reference some id on users table

Related

Laravel Eloquent (eager loadable) custom polymorphic relationship

Using Eloquent, I'm trying to make a polymorphic relationship between some models that isn't working out. Simplified, it works like this: there is a model 'groups', which obviously can contain some groups. Now each of these groups can either contain 'members' or 'guests', so I have a table and model for both of them. These are not similar to each other. My groups table contains a column in which model to use (members or guests). The structure is as follows:
groups (\App\Models\Group)
id
name
model (either \App\Models\Member or \App\Models\Guest)
members (\App\Models\Member)
id
group_id
first_name
last_name
address
email
.....
guests (\App\Models\Guest)
id
group_id
name
So the relationship 'people' in a group retrieves either the members or the guests. Using the default $this->morphTo() function using the group_id is able to retrieve the correct results, but due to its logic only returns one result, while I need all results. The rest of the app is indifferent to whether the people are members or guests, so I do not want to split those two up here.
Any ideas on how to accomplish this? I'm trying to eager load the relationship.

Messaging with two user tables in Laravel

I am developing a system in which it will have a chat system between two user tables: the clients and the engineers. My problem is how to make these two tables communicate in one message table with regard to registering the sender ID and recipient ID since both can change and are in different tables.
My initial thought for this was two tables where I would use the polymorphic relationship:
chats
id
client_id
engineer_id
messages
id
chat_id
senderable_id
senderable_type
receiverable_id
receiverable_type
content
What would be the most recommended way to solve this problem?
First of all, the following its the generic way that I see to create a chat schem. It'll works to a chat with 2 users or more than 2 users.
Note, the user_chat table its the pivot table between users and chats. You can define an alias to that table, like "participants", because it what it means. You can add more attributes to chats table, but basically need to know the creator.
Finally, the secret in messages table is just to get the sender id from users table, because sender and receiver are relative concepts in this context.
Another more simple and reduced way to do it (if you are trying to make a chat with only 2 users) is:

DynamoDB Event Scheduling Table Structure

I'm building out a scheduling app, where users can invite other users to events. However, I'm having a little trouble figuring out how I want to set up my tables.
Since DynamoDB is a NoSQL database we want to try to keep data that is related, in the same table. However, this problem gets a bit more confusing because some events for my app may have roles, such as organizer, planner, etc. Therefore, I want users for an event to be able to accept the invitation to the event with specific roles.
Therefore, in this case, would I want to use two tables, one that stores the event (UUID, Name, etc.) and the other that has the users attending events (UUID of Event, Username, etc.) or use one table?
Plus, when I create my get request to fetch the event data if I use two tables, would I have to query the user table to get the number of people attending that event or should I store that value in the event table, and then when a user signs up, add a new row to the users table, and update the number of people attending in the event table?
For the app I am using Lambda functions on AWS.
Any help would be appreciated, thanks!
You can have
userid as hash-key
eventid as range-key
role as LSI
You can also have a GSI on event-id to query based on eventid
sample table:
user1, event1, organizer
user2, event1, planner
user3, event1, attendee
user4, event1, attendee

Parse How to Group By similar objects in One object?

I am using Parse for Group Chat and Private Chat both.
I get stuck in a situation
where in Chat("one table using for both private and group")
there are columns such as
"Groupid, Senderid, ReceiverId and Status"
Here one user sends more than one text msgs so I want to collect all the chats of that user in One Group so one user can have joined more than 1 groups so I want the all chats of particular group in one bunch so if there are chats in 5 groups then there should 5 objects with their chats such as Group By functionality.

Correct Many to Many friends relationship for users

What is the correct way to relate users in parse to one another as friends?
I also want users to be able to query other users but not see all fields, like emails. Is there a way I can create a view on the users table with cloud code, and only return this to the client code?
I was thinking I can create a friends table that will have two columns with 2 pointers, 1 for each user.
thanks for any advice.
I was thinking I can create a friends table that will have two columns with 2 pointers, 1 for each user.
I'll do that too, with a status column to handle pending, blocked...etc
I also want users to be able to query other users but not see all fields, like emails.
You have to add a privateData column on user with ACL restricted to owner only, which would contain private infos such as emails...etc

Resources