我有玩家和付款模式。在付款表中有" player_id"柱。 我想选择播放器+付款关系的特定属性。换句话说,我想结合这2个查询。
1. User::where(/* some condition */)->with('payment')->get();
2. User::where(/* some condition */)->select([/* some attributes */])->get();
但如果我尝试
User::where(/* some condition */)->select([/* some attributes */])->with('payment')->get();
返回的模型关系数组为空。
答案 0 :(得分:0)
你可以尝试一下 -
`User::where(/* some condition */)->select([/* some attributes of user */])->with(['payment' => function ($q) {
return $q->select(/* some attributes payment */)
}])->get();`
答案 1 :(得分:0)
有点棘手,但应该有效
User::where(/* some condition */)->select([/* some attributes */])->get()->load('payment');