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

Test with:

Message::find(1)->userfrom()->first()->username;
//or
Message::find(1)->userfrom->username;
Last updated 2 years ago.
0

Works with Message::find(1)->userfrom()->first()->username;, thanks.

I figured why it didn't work with Eloquent's dynamic properties: I named the method after the column (userfrom), so $message->userfrom returned the actual column and didn't called the relationship method.

I renamed it from() and now Message::find(1)->from->username works well!

Last updated 2 years ago.
0

Great

Yeah, Relationship names have be different of properties.

Edit the post and put as Solved.

Last updated 2 years ago.
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.