Can't turn an object into an array.

Posted 8 months ago by ChrisF79

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 sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.