Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get all participant Models that a Model ever had a conversation with #304

Open
mooxnl opened this issue Jun 2, 2022 · 0 comments
Open

Comments

@mooxnl
Copy link

mooxnl commented Jun 2, 2022

I'm trying to retrieve a list of all the Models (participants) that a certain Model ever had a conversation with.

My chat screen has 3 columns:

  1. list of contacts (grouped, so each contact is displayed only once and sorted by latest message first)
  2. list of conversations with the selected contact
  3. messages inside the selected conversation

My question is regarding the first column. Is this possible?

I tried it with this query to get all participants for User with id 1, which works, but doesn't group the participants:

Musonza\Chat\Models\Conversation::query()
    ->whereHas('participants', function($query) {
        $query->whereHasMorph(
            'messageable',
            [User::class],
            function ($query) {
                $query->where('id', 1);
            })
            ->groupBy(['messageable_type', 'messageable_id']);
    })
    ->get()
@mooxnl mooxnl changed the title Get all (unique) participants that a model ever had a conversation with Get all participant Models that a Model ever had a conversation with Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant