当兴趣方法存在于模型中时,我在查询中遇到以下错误。
调用未定义的方法Illuminate \ Database \ Query \ Builder :: interest()
控制器:
public function index() {
$user_id = auth()->user()->id;
$user = User::find($user_id);
$interests = Space::where('user_id', $user_id)->interest()->get();
return view('dashboard')->with('space', $user->space)->with('interest', $interests->space);
}
空间模型:
public function user(){
return $this->belongsTo(User::class);
}
public function interest(){
return $this->hasMany(Interest::class);
}
兴趣模式:
public function user(){
return $this->belongsTo(User::class);
}
public function interest(){
return $this->belongsTo(Space::class);
}
慕的地6264312