[英]laravel Greater than other field
I have the record package_id, it is a number field, so I want to check if its not empty or greater than 0 in controller, NOW this is working if package_id=2 in the database but if package_id is null then it will work exactly as if its equal 2 !!! 我有记录package_id,它是一个数字字段,因此我想检查它在控制器中是否不为空或大于0,现在如果数据库中的package_id = 2可以正常工作,但如果package_id为null,那么它将完全正常工作如果等于2! why??
为什么?? and how to check if only greater than 0 or not null
以及如何检查是否仅大于0或不为null
if(Customer::where('customer_id', 'LIKE', $request->customer_id)->where('package_id', 2)->count() > 1) {
//do somthing...
}
You can do like this 你可以这样
$query = Customer::where('customer_id', 'LIKE', $request->customer_id)->where('package_id','>', 0)->count();
if($query > 0){
//do somthing...
}else{
//do somthing...
}
You should try this: 您应该尝试这样:
$query = Customer::where('customer_id', 'LIKE', $request->customer_id)->where('package_id','>', 0)->get();
if(!empty($query) && count($query) > 0){
//Your output
}else{
//Your output
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.