[英]How to create condition based query using Eloquent ORM Laravel?
我可以在类似if条件的情况下使用此代码吗?
$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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.