->toArray() only works on certain laravel objects, like models, not php objects in general.
You could try just typecasting it to an array, but you'd only get visible (public) properties.
$results = (array) $results;
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Just starting to work on something and I have the following code:
class ProcessRetsListings
{
public function __construct($results)
{
$this->results = $results;
}
public function process($results)
{
$results->toArray();
foreach ($results as $result)
{
echo $result['StreetName'];
}
}
}
I ran a php gettype($results) and it is in fact an object. I try to turn it into an array and I get the error: Call to undefined method App\Models\RetsFeedApiResult::toArray()
I need it to be an array so I can work with it and ultimately save the entire result to the database.
Please or to participate in this conversation.