我有一张桌子note
与id, note, type_id, about_id
。这里type_id
指的是像task(601), discussion (602), images (603),
等不同的类型。而about_id
指的是受尊重的类型表的id。
$note = Notes::with('tasks')->with('discussion')->with('images')->get();
这返回了包含所有->with()
表值的注释。如何根据type_id
获取相关表的值。我试过了
$note=Notes::where('deleted_at', null);
$note=$note->WhereHas('tasks', function($q) use($note)
{
$note->Where('type_id',601);
})->get();
是否有可能使用eloquent获取相关的表值。
使用Use($note)
不必要,删除它并使用$q
代替
$note = Notes::where('deleted_at', null)
->whereHas('tasks', function($q){
$q->where('type_id',601);
})->get();
如果你想得到所有相关的->with('tasks')
,还包括tasks