1
我有兩個表users
和user_details
。我有聯繫users
表作爲Laravel關係不工作:getConnectionName()錯誤
public function userDetails()
{
return $this->hasOne('App\Repositories\Models\UserDetails', 'id', 'user_id');
}
和鏈接user_details
表作爲
public function user()
{
return $this->belongsTo('App\Repository\Models\User');
}
雖然從UserController
用於訪問用戶的數據與信息,如果我試圖訪問數據
return $this->user->with('userDetails')->get();
我得到這種類型的錯誤
FatalErrorException in HasRelationships.php line 488: Call to undefined method
App\Repositories\Models\UserDetails::getConnectionName()
有什麼不對嗎?
肯定會的。我用'User :: class'和'UserDetails :: class'。 –