Skip to content

Commit

Permalink
refactor: threadResource mods
Browse files Browse the repository at this point in the history
  • Loading branch information
syntaxlexx committed Jan 17, 2022
1 parent 59c1951 commit fcdc826
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Resources/ThreadResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class ThreadResource extends JsonResource
*/
public function toArray($request)
{
$creator = $this->creator();

return [
'id' => (int) $this->id,
'subject' => $this->subject,
Expand All @@ -29,8 +31,9 @@ public function toArray($request)

'unread_count' => $this->userUnreadMessagesCount(auth()->id()),
'latest_message' => optional($this->latestMessage)->body ?? null,
'creator' => optional($this->creator())->name,
'creator_avatar' => optional($this->creator())->avatar_url,
'creator_id' => $creator->id ?? null,
'creator_name' => $creator->name ?? null,
'creator_avatar' => $creator->avatar_url ?? null,
'participants' => $this->participantsString(auth()->id()),

'messages' => MessageResource::collection($this->whenLoaded('messages')),
Expand Down

0 comments on commit fcdc826

Please sign in to comment.