*/ public function toArray(Request $request): array { return [ 'id' => $this->id, 'uuid' => $this->uuid, 'name' => $this->name, 'email' => $this->email, 'phone' => $this->phone, 'gender' => $this->gender ? 'Male' : 'Female', 'message' => $this->message, 'submitted_at' => $this->submitted_at->format('Y-m-d H:i:s'), 'created_at' => $this->created_at->format('Y-m-d H:i:s'), 'updated_at' => $this->updated_at->format('Y-m-d H:i:s'), 'category' => $this->whenLoaded('category', function () { return [ 'id' => $this->category->id, 'name' => $this->category->name, ]; }), 'comments' => $this->whenLoaded('comments', function () { return $this->comments->map(function ($comment) { return [ 'id' => $comment->id, 'content' => $comment->content, 'user' => $comment->user ? $comment->user->name : 'Anonymous', ]; }); }), 'links' => [ 'self' => route('api.form-data.show', $this->id), 'edit' => route('api.form-data.update', $this->id), 'delete' => route('api.form-data.destroy', $this->id), ], ]; } }