|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Lexx\ChatMessenger\Resources; |
| 4 | + |
| 5 | +use Illuminate\Http\Resources\Json\JsonResource; |
| 6 | + |
| 7 | +class ThreadResource extends JsonResource |
| 8 | +{ |
| 9 | + /** |
| 10 | + * Transform the resource into an array. |
| 11 | + * |
| 12 | + * @param \Illuminate\Http\Request $request |
| 13 | + * @return array |
| 14 | + */ |
| 15 | + public function toArray($request) |
| 16 | + { |
| 17 | + return [ |
| 18 | + 'id' => (int) $this->id, |
| 19 | + 'subject' => $this->subject, |
| 20 | + 'slug' => $this->slug, |
| 21 | + 'start_date' => $this->start_date, |
| 22 | + 'end_date' => $this->end_date, |
| 23 | + 'max_participants' => $this->max_participants, |
| 24 | + 'avatar' => $this->avatar, |
| 25 | + |
| 26 | + 'created_at' => $this->created_at, |
| 27 | + 'updated_at' => $this->updated_at, |
| 28 | + 'deleted_at' => $this->deleted_at, |
| 29 | + |
| 30 | + 'unread_count' => $this->userUnreadMessagesCount(auth()->id()), |
| 31 | + 'latest_message' => optional($this->latestMessage)->body ?? null, |
| 32 | + 'creator' => optional($this->creator())->name, |
| 33 | + 'creator_avatar' => optional($this->creator())->avatar_url, |
| 34 | + 'participants' => $this->participantsString(auth()->id()), |
| 35 | + |
| 36 | + 'messages' => MessageResource::collection($this->whenLoaded('messages')), |
| 37 | + ]; |
| 38 | + } |
| 39 | +} |
0 commit comments