我创建mysql查询,但我没有分页如何在此查询中使用laravel分页

时间:2019-01-31 07:29:34

标签: laravel

我已经创建了MySQL查询来搜索结果。该查询正常运行,但是如果在此查询上使用laravel分页,则会出现错误

  

调用数组上的成员函数paginate()

如何通过分页解决这个问题?

$search = \DB::SELECT("SELECT l.*, 
       r.id          AS reservation_id, 
       r.status      AS res_status, 
       r.start_date, 
       r.end_date, 
       Avg(r.rating) AS rating 
FROM   listings l 
       LEFT JOIN reservations r ON r.listing_id = l.id 
WHERE  ( ( Cast('" . $search_date . "' AS date) NOT BETWEEN r.start_date AND r.end_date )  OR r.status = 'Cancel' ) 
       AND l.city_id = $city_id 
       AND l.persons >= $guests 
       AND l.listing_type_id = $type 
GROUP  BY l.id 
ORDER  BY r.rating DESC 
");

1 个答案:

答案 0 :(得分:0)

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa4 in position 4942: invalid start byte 将返回一个数组。您可能将查询转换为查询生成器,然后在其上使用DB::select()。例如:

paginate()