小编Tij*_*har的帖子

Laravel关系不起作用:getConnectionName()错误

我有两个表usersuser_details.我把users表链接为

public function userDetails()
{
    return $this->hasOne('App\Repositories\Models\UserDetails', 'id', 'user_id');
}
Run Code Online (Sandbox Code Playgroud)

和链表user_details作为

public function user()
{
    return $this->belongsTo('App\Repository\Models\User');
}
Run Code Online (Sandbox Code Playgroud)

来自UserController用于访问用户数据的详细信息,如果我尝试访问数据

return $this->user->with('userDetails')->get();
Run Code Online (Sandbox Code Playgroud)

我遇到了这种错误

FatalErrorException in HasRelationships.php line 488: Call to undefined method

App\Repositories\Models\UserDetails::getConnectionName()
Run Code Online (Sandbox Code Playgroud)

有什么不对的吗?

php relationship relation laravel

3
推荐指数
1
解决办法
2209
查看次数

标签 统计

laravel ×1

php ×1

relation ×1

relationship ×1