當(dāng)興趣方法存在于模型中時(shí),我在查詢中遇到以下錯(cuò)誤。調(diào)用未定義的方法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);}
Laravel未定義方法
桃花長(zhǎng)相依
2021-04-28 17:13:04