messenger
messenger copied to clipboard
When a new thread is created, there is no participants_count value set
When a new thread is created (adding 2 users for testing), this value 'participants_count' is not set. (=> $thread->participants()->count())
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.
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(),