【发布时间】:2018-01-17 04:34:06
【问题描述】:
我正在尝试查找有条件的行,那就是...
一个用户有很多个人资料图片,但只有一张图片是is_main
这就是我写的
public function profile_picture()
{
return $this->hasMany('App\User_profile_picture');
}
public function active_picture()
{
return $this->profile_picture()->find($this->is_main);
}
现在当我通过
访问它时$picture = Auth::user()->active_picture;
上面写着
Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation
我必须做些什么才能让它发挥作用?
【问题讨论】:
-
我可能是错的,但一对多的关系不应该与
with函数一起使用吗? laravel.com/docs/5.4/eloquent-relationships#eager-loading
标签: php laravel laravel-5 eloquent laravel-5.3