Support the ongoing development of Laravel.io →
Database Eloquent Installation
Last updated 2 years ago.
0

Hi Skaya,

First of all i want to point out that in email class personas method relationship you have the person class spalled in correctly Persona.

Secondly, thought i do not know what you want to accomplish with your application, but if you are creating a email application the appropriate relationship would have been:

** Person hasMany Emails ** ** Email belongTo Person ***

In your currently defined relationship it says, single email belongs to many persons, Is that what you really want?

Now to answer your question to why you're getting undefined property when you try to access $person->emails->email is that you are getting back collection of data, therefore, you have to loop through the $person->email object.

I hope this helps.

Thanks.

0

I got it, my brain is not working properly lol.

$person->emails->first()->email;

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.