1
使用此:在Laravel雄辩,为什么这不正确选择(没有条件)?
profile = User::find($user)->with('profile')->first();
将返回,而不是选择属于找到的用户ID的配置文件的SELECT * FROM profiles
查询。
我的用户模型如下:
public function profile() {
return $this->hasOne('App\Models\UserProfile', 'user_id');
}
为什么不添加where
条件?
您是否尝试对它们进行重新排序:User :: with('profile') - > find($ user) - > first();' – TheFallen