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');
The $comment isnt an eloquent object but a stdClass. How do you fetch it in the controller?
@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');
@chrishtoffertyrefors, I'm getting it as an Active Record, using the Model::where() query.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community