Using illuminate/pagination outside laravel

3.2k views Asked by At

I'm building custom project and for now for database connection i used illuminate/database the eloquent model. But i need samo pagination to continue my development i installed via composer illuminate/pagination and i cant configure it propertly i searched all over the internet no documentation for using with illuminate pagination or how to configure it.

I have function

User::all();

Where i fetch all my users successfully but i need to make paginate when i try to use ->paginate() method not found.

The composer is set coorectly and all my files are loaded.

Any tips how to set up the illuminate/pagination library ? Btw i developed custom framework where i have controller and models. All my models are Eloquent models.

Thanks

3

There are 3 answers

1
J. Fekete On

You can check out the forPage() method on the Collection itself. https://laravel.com/docs/5.8/collections#method-forpage

This worked for me:

$collection->forPage($_GET["pagenr"], $perpage);
0
Drew Bartlett On

Not sure if this is helpful anymore, but I was having the same issue and came across this: https://laracasts.com/index.php/discuss/channels/general-discussion/class-paginator-does-not-exist-laravel-42

Seems as though it's not possible outside laravel.

0
milad shaker On

use :

composer require illuminate/pagination

for example : if need Controllers and Models add autoload psr-4

composer.json

{
 "name": "illuminate-example/eloquent",
 "description": "Implementation of Database Queries with illuminate and Eloquent",
 "type": "project",
 "require": {
 "illuminate/database": "^6.17",
  "illuminate/pagination": "^6.17"},
 "autoload":
    {"psr-4":
        { "Controllers\\": "app/controllers/",
            "Models\\": "app/models/"

                 }
    }
}