【发布时间】:2020-09-03 04:43:05
【问题描述】:
我的应用中有以下查询,
public function ExcOrders($driver_id, $from_date, $to_date){
$orders = DB::table('order_details as o')
->join('order_tracker as a','o.id','=','a.oid')
->where('a.owner_id','=',$driver_id)
->whereBetween('a.created_at',[$from_date, $to_date])
->where('o.status',0)
->select([DB::raw('SUM(o.price) as TotalDeposits'),DB::raw('count(o.price) as count')])
->get();
if($orders->count() > 0){
return response()->json(['status_code'=>1000,'data'=>$orders , 'message'=>"null"],200);
}else{
return response()->json(['status_code'=>2000,'data'=>null , 'message'=>"You Have No Orders For Now !"],200);
}
}
它工作正常,并返回所需的结果,但我的问题如返回所示,我需要检查计数值是否大于零,我不能
结果总是如下,
{
"status_code": 1000,
"data": [
{
"TotalDeposits": null,
"count": 0
}
],
"message": "null"
}
任何帮助将不胜感激
【问题讨论】:
-
您使用的是
->get();,这意味着可能有多个结果。如果是多个,您将如何确定count > 0- 是否至少其中之一?所有这些? -
@Ersoy 结果只有 TotalDeposits 和计数,我需要检查计数值
-
所以你返回一个结果,然后不需要使用 get - 我将发布作为答案