Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

I think your definition is mixed. In use it should be

return $this->hasMany('Comments','created_by', 'id' );

And commen

treturn $this->belongsTo('User', 'id', 'created_by');

Last updated 1 year ago.
0

The $comment isnt an eloquent object but a stdClass. How do you fetch it in the controller?

Last updated 1 year ago.
0

@tzookkb, Yup, I hadn't given the extra foreign key parameter in the relationship! Typically the ordering of parameters works out to be:

For any model, $this-><Desired Relationship>('Related Model', 'Foreign key of the model', 'Primary key of the related model');

Last updated 1 year ago.
0

@chrishtoffertyrefors, I'm getting it as an Active Record, using the Model::where() query.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ananth99 ananth99 Joined 7 Feb 2014

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.