am trying to port my laravel4 application to laravel 5 . In the previous version i could use the following method for generating pagination urls .
In controller:
$this->data['pages']= Page::whereIn('area_id', $suburbs)->where('score','>','0')->orderBy('score','desc')->paginate(12);
and after sharing the data array with the view, i could user
In views :
{{$pages->links()}}
In laravel 5 the doing that results in following error
ErrorException in AbstractPaginator.php line 445: call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Support\Collection' does not have a method 'links'
not sure what i am missing here, can somebody help ?
Just to say (Laravel doc): When manually creating a paginator instance, you should manually "slice" the array of results you pass to the paginator. Could you explain parameters please? The parameters are discussed over the construct method: laravel.com/api/5.0/Illuminate/Pagination/…
In your case you can use $articles->links() in your view to generate the pagination navigation buttons. But if you want to manually set the page then you can do this. $articles = Articles::paginate(5, ['*'], 'page', $pageNumber); The default paginate method takes the following parameters.
To perform pagination in laravel, you just have to use the paginate () function instead of all () or get() functions as used in maximum time. Paginate method takes a number as a parameter. It defines how much data you want to show on one page or section.
In Laravel 5 there is no method "links" you can try this
{!! $pages->render() !!}
In other frameworks, pagination can be very painful. Laravel 5 makes it a breeze. For using it, first you have to make a change in your controller code where you calling data from the database:
public function index() { $users = DB::table('books')->simplePaginate(5); //using pagination method return view('index', ['users' => $users]); }
...after that you can use this code:
<?php echo $users->render(); ?>
That will make you use simple Laravel 5 beauty.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With