[英]Laravel Eloquent select in with empty
我在用戶 Model 中的關系
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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.