私は次の行使用してクエリを作ってるんだ:サブクエリ - ウィッヒ()
$items = $this->model->with('subCategory')->get();
をしかし、私はちょうどからアイテムを取得したいので、私は、the with()
メソッド内のクエリを入れたいですwith()
ステータスが0に等しい場合
これをどのように達成できますか?
私は次の行使用してクエリを作ってるんだ:サブクエリ - ウィッヒ()
$items = $this->model->with('subCategory')->get();
をしかし、私はちょうどからアイテムを取得したいので、私は、the with()
メソッド内のクエリを入れたいですwith()
ステータスが0に等しい場合
これをどのように達成できますか?
これらはeagarload制約と呼ばれ、あなたは私はあなたが乗る方法を知ってみましょう
$items = $this->model->with(['subCategory'=>function($q){
$q->whereId('5');
//or any other valid query builder method.
}])->get();
例えば閉鎖
を使用して結果を得ることができます。
L5のドキュメントには「eager loading」があります。 Here
$items = $this->model->with(['subCategory' => function ($query) {
$query->where('status', 0); }])->get();
多分 - http://stackoverflow.com/a/38371708/6569866 –