lundi 28 février 2022

Laravel Model Relationships Outside Controllers Become Array Instead of Objects

Accessing an attribute of a model's relationship through:

$someModel->itsRelationship->itsRelationshipAttribute

throws the error:

Trying to get property 'itsRelationshipAttribute' of non-object

It works inside Controllers, but anything (at least in web.php or my custom service / helper files) outside of Controllers need to use $someModel->itsRelationship['itsRelationshipAttribute']. Is there some sort of binding (or whatever) that I need to be aware of?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire