hazaveh.net
Laravel 5: Manual Pagination From Array. | Mahdi Hazaveh
Laravel documents is not covering anything about making a pagination from your custom array. its very nice and easy to use pagination out of the box with eloquent queries, but if you want to know how to do it with your custom arrays then you might find it hard searching around in their website. Anyway here is the easy and workable way of making a pagination out of your custom data array. As the Laravel docs says you can either use Illuminate\Pagination\LengthAwarePaginator or use Illuminate\Pagination\Paginator which in this tutorial I'm going to use LengthAwarePaginator. So I'm going to call it in via: [crayon-5c6e5c3d95682435671401/] Lets assume we want to paginate an array called $users. [crayon-5c6e5c3d9568e276771281/] Firstly create an variable holding current page value: [crayon-5c6e5c3d95690875256155/] Now Lets convert our array into a Laravel Collection. This will allow us to use slice and other methods on the data later on. Don't forget to bring in the collection class.