Level 11
Here's the solution:
$result->getData(); // This fails.
$result->getData()->data; // this works
No idea why, but it works.
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hopefully a simple question...but this one has been driving me a bit nuts. I am trying to retrieve the return data from an API response. In this example, hardcoded to:
$returnData=[];
// $returnData['posts'] = null;
$result = (new PostResource($returnData))->response()->setStatusCode(Response::HTTP_OK);
return $result; // this is what the API returns
If the caller tries to access the API return data like this:
$result->getData(); // This fails.
Error:
UnexpectedValueException: The Response content must be a string or object implementing __toString(), "object" given.
Why??
Here's the solution:
$result->getData(); // This fails.
$result->getData()->data; // this works
No idea why, but it works.
Please or to participate in this conversation.