关系方法必须在laravel雄辩中返回一个对象

问题描述 投票:0回答:4

我试图找到一个有条件的行,那是......

用户有很多个人资料图片,但有一张图片是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

我需要做些什么才能使它发挥作用?

php laravel laravel-5 eloquent laravel-5.3
4个回答
© www.soinside.com 2019 - 2024. All rights reserved.