【发布时间】:2015-10-21 22:51:45
【问题描述】:
在我的 Room 对象中,我想获得优先级最低的图片。所以我添加了我的房间模型:
public function picture(){
Return Picture::where('room_id', $this->id)->orderBy('priority', 'asc')->first();
}
在我的控制器中,我将此方法称为:
public function($id){
$room = Room::findOrFail($id);
$room->picture();
}
但是当我试图在我的视图中得到它时:
{{$room->picture}}
我收到以下错误:
关系方法必须返回 Illuminate\Database\Eloquent\Relations\Relation 类型的对象
使用 {{$room}} 时,我在房间对象中看不到任何图片对象,但应用程序没有崩溃。
【问题讨论】:
标签: php laravel laravel-5 eloquent