vendredi 28 juillet 2017

Laravel and algolia, ignore array if null

I have this code:

public function toSearchableArray()
{
    $data = $this->toArray();
    $data['_geoloc'] = $this->_geoloc->toArray();
    $data['address'] = $this->address->toArray();
    return $data;
}

However sometimes $data['entities'] is null therefore throwing me an error:

 [Symfony\Component\Debug\Exception\FatalThrowableError]
  Call to a member function toArray() on null

Is there any way to by-pass that?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2v5IMbN
via IFTTT

Aucun commentaire:

Enregistrer un commentaire