我在用户模型中的关系
public function fullName()
{
return $this->hasOne(UserProfile::class,'user_id','id')->where('slug', '=', 'full_name');
}
$user = User::query()with('fullName:slug')->get();
我的结果:
'full_name' => null
我建议您查看文档
使用此功能时,应始终在要检索的列列表中包括id列和任何相关的外键列。
$user = User::query()->with('fullName:id,slug')->get();