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

how to get conversations with unreadCount #310

Open
samehdoush opened this issue Sep 27, 2022 · 1 comment
Open

how to get conversations with unreadCount #310

samehdoush opened this issue Sep 27, 2022 · 1 comment

Comments

@samehdoush
Copy link

How can I add unreadCount to

$chats =   Chat::conversations()->setPaginationParams([
            'page' => request()->get('page', 1),
            'perPage' => 10,
            'sorting' => "desc",
            'columns' => [
                '*'
            ],
        ])
            ->setParticipant(request()->user())
            ->get();

@michaelgatuma
Copy link

You can use a conversation transformer then implement your transformer like this:

//

public function transform($conversation): array
    {
        return [
            'id' => $conversation->id,
            'unread_count' => Chat::conversation($conversation)->setParticipant(\Auth::user())->unreadCount(),
            'private' => (bool)$conversation->private,
            'direct' => (bool)$conversation->direct_message,
            'data' => $conversation->data,
        ];
    }

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

2 participants