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-5ceacf04539f7942071118/] Lets assume we want to paginate an array called $users. [crayon-5ceacf0453a09242808673/] Firstly create an variable holding current page value: [crayon-5ceacf0453a0c138227338/] 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.