-1
如果条件如此,我可以使用此代码吗?如何使用Eloquent ORM Laravel创建基于条件的查询?
$testq= DB::table('attendances')
if($flag==1)
->where('type', '=', $userinput)
else
->where('type', '=', $newdate)
->get();
如果条件如此,我可以使用此代码吗?如何使用Eloquent ORM Laravel创建基于条件的查询?
$testq= DB::table('attendances')
if($flag==1)
->where('type', '=', $userinput)
else
->where('type', '=', $newdate)
->get();
你可以。这会为你工作:
$query = DB::table('attendances');
if($flag == 1) {
$query->where('type', '=', $userinput)
} else {
$query->where('type', '=', $newdate)
}
$result = $query->get();
它的工作thankx一个looooooooooooot – sara