【问题标题】:Laravel pagination with rawLaravel 使用 raw 进行分页
【发布时间】:2020-05-11 09:39:12
【问题描述】:

我只是想问一些与 laravel 分页有关的事情。 我有这行代码 DB::select(DB::raw('my query here')); 在我的控制器中,但我想对这个查询的结果进行分页。有可能吗?

更新:这是我的实际代码。

  $query = "SELECT
                * 
            FROM
                bil_tbl_billing_service_item AS bil_service_item
                INNER JOIN bil_tbl_billing AS billing ON billing.ID = bil_service_item.billing_id

                INNER JOIN dblink
                ('pofsis_business', 
                'SELECT
                        service_item.id as service_item_id,
                        service_item.series_num as service_item_series_num,
                        service_item.name as service_item_name,
                        service_item.particular as service_item_particular,
                        service_item.amount as service_item_amount,
                        vat_type.type as service_item_vat_type,
                        vat_type.rate as service_item_vat_rate
                    FROM
                        biz_tbl_service_item AS service_item
                        INNER JOIN biz_tbl_service_item_other as service_item_other on service_item_other.service_item_id = service_item.id
                        INNER JOIN biz_tbl_vat_type as vat_type on vat_type.id = service_item_other.type_of_vat_id') as service_item (service_item_id INTEGER, service_item_series_num VARCHAR, service_item_name VARCHAR, service_item_particular VARCHAR, service_item_amount NUMERIC, service_item_vat_type VARCHAR, service_item_vat_rate INTEGER) ON service_item.service_item_id = bil_service_item.service_item_id

                WHERE billing.active = 1";
    if($billingId !== null) {
        $query = $query." AND billing.id = $billingId";
    }
    return db::select(db::raw($query));

【问题讨论】:

  • 你能不能把它改成查询生成器并运行
  • 把你的sql查询放在这里
  • 请看我更新的帖子。你认为我可以使用查询生成器做到这一点吗?

标签: laravel pagination


【解决方案1】:

如果查询正常工作并为您提供结果

这样做分页

DB::select(DB::raw('my query here'))->paginate(10);

【讨论】:

  • 它给了我这个错误'Call to a member function paginate() on array'。
猜你喜欢
  • 2014-09-01
  • 2015-01-01
  • 2020-04-21
  • 1970-01-01
  • 1970-01-01
  • 2018-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多