vendredi 25 mai 2018

Many-to-many relationship. How to search one common for 2 collections?

I have many-to-many relationship in my project. user belongsToMany chats and chat belongsToMany users.

So, i have a pivot table chat_user with chat_id and user_id.

One chat can include some users as well

Its ok and works well.

When i`m creating a new Chat, i have 2 users. And i want to check, is there already common chat between them.

I have some problems with this query. I also tried to make custom model on chat_user table..but has no luck=( May be someone has done such work? Is there any practicies? Thank you!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire