3

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

mstojanov
  • 175
  • 4
  • 17

3 Answers3

1

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);
J. Fekete
  • 11
  • 2
  • I think you shouldn't use illuminate/pagination for this use-case. It is much easier to implement what you want with forPage() method. – J. Fekete Sep 04 '20 at 13:15
0

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/"

                 }
    }
}
-1

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.

Drew Bartlett
  • 1,863
  • 5
  • 23
  • 37