简体   繁体   中英

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 !!! why?? and how to check if only greater than 0 or not 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
      } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM