I am new to Laravel 4.2.
I need to do some pagination in my view search result page.
What I am doing is writing this code in the controller -
public function getSpecials()
{
$title = "Specials";
$info = DB::table(DB::raw('`car` , `available_car`, `users`'))
->select('car.car_maker', 'car.car_model', 'available_car.car_price', 'car.car_production_year', 'available_car.car_id', 'available_car.id', 'available_car.current_position')
->where('available_car.car_id', '`car`.`car_id`')
->where('available_car.is_sold', 'no')
->whereRaw('`available_car`.`created_at` BETWEEN NOW() - INTERVAL 30 DAY AND NOW()')
->orderByRaw('WEEK(`available_car`.`created_at`) DESC')
->orderBy('available_car.car_price', 'desc')
->orderBy('users.last_paid_date', 'desc')
->orderBy('available_car.created_at', 'desc')
->distinct()
->get();
$pagination = Paginator::make($info, count($info), 5);
//var_dump($pagination );
return View::make('specials',compact('pagination'))->with('info',$info)->with('title',$title);
}
I want to show 5 items per page. So I am doing paginate like this -
$pagination = Paginator::make($info, count($info), 5);
But the problem here is I am getting paginate number in the page perfectly. But, All page is showing the whole result, not showing only 5 items.
It is the output. (paginate is for 5 items per page and total no of entry is 7 in my case)
Page 1
Page 2
Can anyone help me please? Thanks in advance for helping.
get()
, usepaginate(5)
. you have a direct query builder object. you can chain it. if you want to go custom way, you have to again add skip and take and calculate them from the page parameter. – itachi