简体   繁体   English

laravel比其他领域更大

[英]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.

相关问题 确保 Laravel 中的一个输入字段大于另一个 - Making sure one input field is greater than the other in Laravel Laravel 4.2验证输入必须大于其他输入 - Laravel 4.2 validation input has to be greater than other input Laravel:验证需要大于另一个的 integer 字段 - Laravel: validate an integer field that needs to be greater than another 如何在MongoDB中选择一个字段大于其他字段的文档? - How to select documents with one field greater than other in MongoDB? 如何使用 Laravel 中的验证使输入日期字段大于或等于另一个日期字段 - how to make an input date field greater than or equal to another date field using validation in laravel Laravel 验证一个字段大于或等于另一个字段不起作用 - Laravel validation of one field being greater than or equal to another field not working Laravel 在视图中大于或等于 - Laravel Greater than or equal in views 原则,领域大于价值 - Doctrine, field greater than value Laravel5.1:验证时间字段(开始时间应大于结束时间) - Laravel5.1: validate time field (start time should be greater than end time) (laravel)是否可以通过传递除id之外的字段来使用方法注入? - (laravel) Is it possible to use method injection by passing a field other than the id?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM