Level 15
Looks good - though you will need pivot tables in your database design - for cases where you have many to many relationships
Hi all,
Am having a hard time to find out how to structure my tables and my relationships when creating a simple chat feature for my app.
I want it to be able to chat from both User to Clients and Clients to User ( I've added so they are both able to login to the system)
Here is my design so far. Can anyone see if am missing something?
Participant (pivot table)
Message
Conversation
public function conversation()
{
return $this->belongsTo(Conversation::class);
}
public function sender()
{
return $this->morphTo();
}
public function conversation()
{
return $this->belongsTo(Conversation::class);
}
public function participants()
{
return $this->hasMany(Participant::class);
}
public function messages()
{
return $this->hasMany(‘App\Chat\Message’);
}
public function messages()
{
return $this->morphMany(Message::class, ‘sender’);
}
public function conversations()
{
return $this->hasMany(Conversation::class);
}
public function participants()
{
return $this->belongsToMany(Participant::class);
}
public function messages()
{
return $this->morphMany(Message::class, ‘sender’);
}
public function conversations()
{
return $this->hasMany(Conversation::class);
}
public function participants()
{
return $this->belongsToMany(Participant::class);
}
Please or to participate in this conversation.