Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql Laravel检查查询计数值_Mysql_Laravel_Lumen - Fatal编程技术网

Mysql Laravel检查查询计数值

Mysql Laravel检查查询计数值,mysql,laravel,lumen,Mysql,Laravel,Lumen,我的应用程序中有以下查询 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','=',$drive

我的应用程序中有以下查询

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);
        }
    }
它工作正常,并返回所需的结果,但我的问题如return中所示,我需要检查计数值是否大于零,我不能

结果总是如下所示

{
    "status_code": 1000,
    "data": [
        {
            "TotalDeposits": null,
            "count": 0
        }
    ],
    "message": "null"
}
任何帮助都将不胜感激

尝试以下方法:

$orders = $orders->reject(function ($order) {
    // do somthing ...
    return $order->data->count >= 'some condition you like';
})
->map(function ($order) {
    // do somthing ...
    return $order;
});

您正在使用->获取;这意味着可能会有几个结果。如果是多个,您将如何确定计数是否>0-至少其中一个?所有这些?@Ersoy结果只是全部存款和计数,我需要检查计数值,因此您将返回一个结果,无需使用get-then-我作为回复发布感谢,但我没有得到1个原始结果!,我需要查询以获得所有匹配RAW的条件的总和和计数,请检查我的输出如何获得计数值这就是我想要的need@AliAdil如果您的响应是数组,但每次只有一个元素,则不需要将其作为数组。如果是数组,但有多个对象由{totalDeposits and count}组成,那么如何确定计数>0。因为有些可能是零,有些可能大于零。我只是想说清楚,但正如我所知,第一个函数只会选择第一个匹配查询的原始数据?!在我的例子中,我有几个rawsokay,所以我不能在我的例子中使用它,因为正如我提到的,我有几个raw,因此我必须使用getLets来表示这是响应[{TotalDeposits:null,count:0},{TotalDeposits:2,count:2},{TotalDeposits:1,count:1}]有两行>0,一行为0-您希望如何进行比较,并做出什么决定?至少有一行的值>0或所有行>0或其他@AliAdil
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')])
        ->first(); //replaced get here 

    if ($orders->count > 0) { // check here - if you need you may check $orders first too 
        return response()->json(['status_code' => 1000, 'data' => $orders, 'message' => "null"], 200);
    }

    return response()->json(['status_code' => 2000, 'data' => null, 'message' => "You Have No Orders For Now !"], 200);
}