DmitriySemenov's avatar

Laravel returning array with "belongsTo" eloquent relationship instead of object

Hi! Who can help me? On my project on v5.2. Laravel returning array with "belongsTo" eloquent relationship instead of object. Why?

0 likes
6 replies
topvillas's avatar

So you can manipulate the result of the relationship further.

DmitriySemenov's avatar

I have this relation method in model Subscribe

public function section() { return $this->belongsTo('App\Section'); }

when i call it in view i get array

I can't get property as {{$subscribe->section->name}}, only as

{{$subscribe->section['name']}}

ismar's avatar

I had this issue and the problem was that my relationship was named 'original' and it was conflicting with the already existing $original property on the model which is actually what is returned from $model->original, hence the array data. Renaming the relationship solved the problem.

Please or to participate in this conversation.