我試圖找到條件的行,這是返回一個對象...關係法必須laravel雄辯
用戶有很多的個人資料照片,但有一個畫面是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'函數? https://laravel.com/docs/5.4/eloquent-relationships#eager-loading –