How to use pagination in Laravel

In this tutorial I will explain to you how you can use pagination in Laravel's projects. In my last tutorial I will write a simple way to extract and display data from database.

I have writed this code:

$data = Data::all(); // this code will extract all information from my table
return View::make('page')->with(array('data'=>$data));

in my Controller, and this code:

@foreach($data as $info)
{{$info->info}}

@endforeach;

in my vieew file.

To use pagination, I will change the code:

$data = Data::all(); // this code will extract all information from my table
return View::make('page')->with(array('data'=>$data));

with

$data = Data::pagination(2); // will extract only two results
return View::make('page')->with(array('data'=>$data));

and

@foreach($data as $info)
{{$info->info}}

@endforeach;

with

@foreach($data as $info)
{{$info->info}}
@endforeach;

{{$data->links()}}

Video tutorial:









Leave a Comment