在我的项目中,我已将 DB:select 与UNION 六个表和 ORDER BY 一起使用。如何在Laravel框架中向此查询添加分页?
我已经尝试过使用Laravel文档分页,但是使用六个表的UNION查询无法分页。
public function publishAds()
{
$id = Auth::user()->id;
$data = City::all();
$ads = DB::select("(SELECT id,title,updated_at,'Commercial Properties' as
'type',town,city,rent_per_month,image1,add_status,'commercial_properties' as
tableName,type as adType from commercial_properties WHERE add_status='published'
AND user_id=$id) union (select id,title,updated_at,'House',town,city,rent_per_month,
image1,add_status,'houses',type from houses WHERE add_status='published'
AND user_id=$id ) union (select id,title,updated_at,'Land',town,city,rent_per_month,
image1,add_status,'lands',type from lands WHERE add_status='published'
AND user_id=$id ) union (select id,title,updated_at,'Apartment',town,city,
rent_per_month,image1,add_status,'apartments',type from apartments
WHERE add_status='published' AND user_id=$id ) union (select id,title,updated_at,
'Holyday Rental',town,city,rent_per_month,image1,add_status,'holyday_rentals',
type from holyday_rentals WHERE add_status='published' AND user_id=$id ) union
(select id,title,updated_at,'Room',town,city,rent_per_month,image1,add_status,
'rooms',type from rooms WHERE add_status='published' AND user_id=$id ) order
by updated_at DESC,rand()");
return view('admin/my-add', ['ads' => $ads, 'cities' => $data, 'status' => 'Publish Ads']);
}
我想为包含六个UNION的该查询分页。