我有一个获取官员凭据的查询,尽管如果用户有的话,它可能会返回许多行。
我正在尝试获取一个查询,其中 IF 行 renew
列之一设置为 1
然后忽略它,否则,如果仍然则返回结果>0
$officiants = Officiant::where('status', 1)
->whereHas('cred',function($q) {
$q->where('renewal', 0);
})
->get();
最佳答案
$officiants = Officiant::where('status', 1)
->whereHas('cred',function($q) {
$q->where('renewal', 0);
})->with([‘cred’=> function($query) {
$query->where('renewal', 0);
})
->get();
如果您想获得信誉,那么您需要此查询。
关于mysql - Laravel - 具有关系多行的 SQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50118364/