*/ public function toArray(Request $request): array { // Quando carregado via forUser(), 'recipients' já vem filtrado pelo // usuário logado — usamos essa linha para o estado de leitura. $recipient = $this->whenLoaded('recipients', fn () => $this->recipients->first()); return [ 'id' => $this->id, 'notification_type' => $this->notification_type, 'title' => $this->title, 'message' => $this->message, 'url' => $this->url, 'action_text' => $this->action_text, 'priority' => $this->priority, 'unit_id' => $this->unit_id, 'franchisee_id' => $this->franchisee_id, 'is_read' => $recipient ? (bool) $recipient->is_read : false, 'read_at' => $recipient?->read_at ? Carbon::parse($recipient->read_at)->format('Y-m-d H:i:s') : null, 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'), ]; } /** * @param \Illuminate\Database\Eloquent\Collection $resource * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection */ public static function collection($resource): AnonymousResourceCollection { return parent::collection($resource); } }