UsmanBasharmal's avatar

Laravel 8 pagination return the same data (offset is ignored - it is always zero)

I have code like this in controller:

$MyItems = App\Models\MyItems::paginate(10);

On URL https://example.com/my-item it will execute SQL:

array:2 [▼
  0 => array:3 [▶]
  1 => array:3 [▼
    "query" => "select * from `teams` order by `name` asc limit 10 offset 0"
    "bindings" => []
    "time" => 0.33
  ]
]

On URL https://example.com/my-item?page=3 it will be the same SQL and the same data in respond. For some reason offset is always "0". Where did I turn wrong?

0 likes
4 replies
MichalOravec's avatar

The code should be like this

$MyItems = App\Models\MyItems::paginate(10);
UsmanBasharmal's avatar

That is just a typo I made while simplifying the question, sorry

Please or to participate in this conversation.