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

标签 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(), 我应该怎么做才能解决这个问题? 非常感谢...

最佳答案

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

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

您可以通过使用带有运算符 >= 和 <= 的常规 where 子句来解决此问题。

关于laravel - 调用未定义的方法 Illuminate\Database\Query\JoinClause::whereBetween(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37296237/

相关文章:

php - Laravel Eloquent wherePivot 方法返回未找到列 'pivot'

php - 如何在 Laravel 5 中执行查询? DB::getQueryLog() 返回空数组

php - Laravel:自定义登录重定向到/home 而不是/welcome 页面

javascript - 如何在 Laravel Blade 文件中 init() JS

php - 在 Laravel 5 中获取数据库条目时的编码问题

mysql - 从 table1 检索数据但在 table2 中进行比较 - Laravel Eloquent

laravel-5 - Laravel 使用 Route::resources 时出错 ('book' 、 'BookController' );

php - Laravel 加入最新的 pressureMap 入口

Cakephp3.1 : Using matching() and notMatching() on the same associated model at once

php - 如何使用 `where` 子句在 Laravel 5 中执行连接?