ChatResource.php 544 B

12345678910111213141516171819202122
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Http\Resources\Json\JsonResource;
  5. class ChatResource extends JsonResource
  6. {
  7. /**
  8. * Transform the resource into an array.
  9. *
  10. * @return array<string, mixed>
  11. */
  12. public function toArray(Request $request): array
  13. {
  14. return array_merge(parent::toArray($request), [
  15. 'title' => $this->title ?? 'Новый чат',
  16. 'messages' => MessageResource::collection($this->whenLoaded('messages')),
  17. ]);
  18. }
  19. }