Skip to content

When a new thread is created, there is no participants_count value set #86

Description

@Sandbird

When a new thread is created (adding 2 users for testing), this value 'participants_count' is not set. (=> $thread->participants()->count())

Image

If I refresh the page though, then I get this information. The participants_count is still missing, but i can use the data.resources.participants.meta.total value.

Image

Not sure how else to retrieve the value, but in order to do it I added, in rtippin\messenger\src\Models\Thread.php:

    /**
     * Get the participants count directly
     *
     * @return int
     */
    public function getParticipantsCountAttribute(): int
    {
        return $this->participants()->count();
    }

and then in rtippin\messenger\src\Http\Resources\ThreadResource.php, right after
'latest_message' => $this->addRecentMessage(), i added:
'participants_count' => $this->getParticipantsCountAttribute(),

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions