| 123456789101112131415161718192021222324252627282930 |
- <?php
- namespace App\Http\Resources;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- class ChatResource extends JsonResource
- {
- /**
- * Transform the resource into an array.
- *
- * @return array<string, mixed>
- */
- public function toArray(Request $request): array
- {
- $title = $this->title;
- if(!$title && $this->created_at->diffInMinutes(now()) > 5) {
- $title = 'Новый чат';
- }
- return array_merge(parent::toArray($request), [
- 'title' => $title,
- 'messages' => MessageResource::collection($this->whenLoaded('messages')),
- 'created_at' => $this->created_at?->format('Y.m.d H:i:s'),
- 'updated_at' => $this->updated_at?->format('Y.m.d H:i:s')
- ]);
- }
- }
|