Skip to content

Commit fcdc826

Browse files
committed
refactor: threadResource mods
1 parent 59c1951 commit fcdc826

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Resources/ThreadResource.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class ThreadResource extends JsonResource
1414
*/
1515
public function toArray($request)
1616
{
17+
$creator = $this->creator();
18+
1719
return [
1820
'id' => (int) $this->id,
1921
'subject' => $this->subject,
@@ -29,8 +31,9 @@ public function toArray($request)
2931

3032
'unread_count' => $this->userUnreadMessagesCount(auth()->id()),
3133
'latest_message' => optional($this->latestMessage)->body ?? null,
32-
'creator' => optional($this->creator())->name,
33-
'creator_avatar' => optional($this->creator())->avatar_url,
34+
'creator_id' => $creator->id ?? null,
35+
'creator_name' => $creator->name ?? null,
36+
'creator_avatar' => $creator->avatar_url ?? null,
3437
'participants' => $this->participantsString(auth()->id()),
3538

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

0 commit comments

Comments
 (0)