Colin Stadig
Colin Stadig

Reputation: 245

Laravel - Undefined property: stdClass::$text

Why would $text be providing an Undefined Property error?

If I run dd($mentions) prior to the function it definitely exists and contains the text property.

If I run dd($mention->text) before return and in the function I also get what is expected.

However, the function will not return a value for $text and instead errors out.

   $text = $mentions->map(function ($mention) {
        return $mention->text;
    });

Upvotes: 0

Views: 1127

Answers (1)

Donii Hoho
Donii Hoho

Reputation: 381

I'd bet that you have 1 object in the $mentions collection that doesn't have the ->text property ?

Try:

   if(!isset($mention->text)){
       dd($mention))
   }

to find out which one.

Upvotes: 1

Related Questions