我想从主模型以及所有相关子模型中检索特定列,如下所示,
public function entries() {
return $this->hasMany('App\AwardEntry', 'award_id')
->join('users', 'users.id', 'user_id')
->where('users.department_id', Auth::user()->department_id)
->with(['files', 'reviews', 'user']);
}
这与 Award::with('entries')->findOrFail($id)
配合得很好。
现在我想从条目表及其所有子关系模式中检索entry_status
。
所以我添加了 select
语句,如下所示,
->select('award_entries.status')
现在工作正常,但 entries
返回空列表。
最佳答案
试试这个:
Award::select('award_entries.status')->where('id', $id)->with('entries')->get();
关于php - 在 Laravel Eloquent 中选择特定列以及所有相关模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45077519/