In my project I have been used DB:select with UNION six table and ORDER BY . How can I add pagination to this query in the Laravel framework?
I already try with Laravel documentation pagination, but it cannot get pagination with six table UNION query.
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']);
}
I want to get pagination for this query which includes six UNION.