[英]Conditional Laravel Eloquent relation
我有一个id, note, type_id, about_id
的表note
。 在这里, 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();
是否有可能仅雄辩地获得相关表的值。
不需要使用Use($note)
,删除它并使用$q
$note = Notes::where('deleted_at', null)
->whereHas('tasks', function($q){
$q->where('type_id',601);
})->get();
如果要获取所有相关tasks
还包括->with('tasks')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.