在1個工作時,我一直在Laravel 5收到此錯誤:1的數據庫關係:1:Laravel 1間的關係返回未定義的屬性
Undefined property: Illuminate\Database\Eloquent\Collection::$owner
在我的控制,我有方法的「東西」。當我返回$東西我得到:
[{"id":4,"demoId":2,"slug":"loremipsum","languageId":1,"countryId":1,"created_at":"-0001-11-30 00:00:00","updated_at":"-0001-11-30 00:00:00"}]
關係是「demoId」。
在我的模型,我有這樣的:
public function owner(){
return $this->belongsTo('App\Demotable2');
}
我使用這個代碼,這給出了一個錯誤:
$routine = $stuff->owner->get()->toArray();
我希望得到的demotable2的信息。我做錯了什麼?
爲@smartrahat說,你應該把'owner'方法在模型中,而不是在你的控制器 – tacone