0

I'm using Eloquent ORM v5.8.29 without Laravel in my PHP project. I've done so by including "illuminate/database": "^5.8" in my composer.json file. It's been working fine so far, creating models and executing Eloquent statements on those Models to get the data I want out of my MySQL database. However, whenever I try to use the pagination feature from Eloquent, I run into trouble.

Example code

class UseCaseController
{
    public function getAllPaginated($amountItems)
    {
        return UseCase::where('active', '1')->paginate($amountItems);
    }
}

PhpStorm IDE throws the following error:

Undefined class Paginator

I've tried a few suggestions for other paths, but no easy fix has presented itself. There seems to be pagination included with Eloquent, so I'm assuming this works without Laravel or Blade templating. Am I wrong here? Is Laravel a required component, or am I doing something else wrong?

Karl Hill
  • 12,937
  • 5
  • 58
  • 95
Seroczynski
  • 472
  • 1
  • 4
  • 14
  • 2
    You need to install `illuminate/pagination` and set a page resolver: https://stackoverflow.com/a/52374272/4848587 – Jonas Staudenmeir Oct 02 '19 at 12:29
  • @JonasStaudenmeir Thanks! I had to update illuminate/database to ^6.0 and was able to install the package you mentioned. However, I am having trouble getting the page resolver to function. I have my application separated as API and front-end. Where would I have to define the page resolver? I'm unable to get this answer from the link you've posted. – Seroczynski Oct 03 '19 at 13:50
  • You need to define the page resolver *before* you call `paginate()`. – Jonas Staudenmeir Oct 03 '19 at 13:55

0 Answers0