*/ 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') ]); } }