调用未定义的方法Illuminate \ Database \ Query \ JoinClause :: whereBetween()

时间:2016-05-18 09:59:22

标签: laravel laravel-5 query-builder

在我的情况下,我想显示某些用户完成的订单, 在一定的时间范围内, 这是我的代码

$orders = DB::table('user_profiles')
            ->leftJoin('orders', function($join) use ($status,$order){
                $join->on('user_profiles.id','=','orders.id_user')
                    ->where('orders.status','=',$status)
                    ->whereBetween('orders.created_at',[$from,$to]);
            })
            ->selectRaw('user_profiles.*, count(orders.id_user) as order_try_count')
            ->groupBy('user_profiles.id')
            ->orderBy('order_try_count',$order)
            ->paginate(15);

但是我调用了未定义的方法Illuminate \ Database \ Query \ JoinClause :: whereBetween(), 我该怎么做才能解决这个问题? 非常感谢你......

2 个答案:

答案 0 :(得分:0)

您没有错误,只是JoinClause没有whereBetween()方法。

https://laravel.com/api/5.2/Illuminate/Database/Query/JoinClause.html

您可以通过使用带有运算符> =和< =。

的常规where子句来解决此问题。

答案 1 :(得分:0)

没有方法调用'whereBetween'使用'whereIn'

$orders = DB::table('user_profiles')
        ->leftJoin('orders', function($join) use ($status,$order){
            $join->on('user_profiles.id','=','orders.id_user')
                ->where('orders.status','=',$status)
                ->whereIn('orders.created_at',[$from,$to]);
        })
        ->selectRaw('user_profiles.*, count(orders.id_user) as order_try_count')
        ->groupBy('user_profiles.id')
        ->orderBy('order_try_count',$order)
        ->paginate(15);