0

SOLVED. My nginx configuration was wrong and now it is fixed.

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?

Yevgen
  • 1,239
  • 3
  • 15
  • 30
  • 1
    This is really strange... try checking if you are getting the `page` query parameter, maybe you have a problem there so it is not sending `?page=123` to the server so Laravel only sees like you are on first page all the time (this happened to me in a project where I was not able to configure CDN, so person who did it, did it wrong...) – matiaslauriti Mar 31 '21 at 10:12
  • Yes, you are right. It turns out it is not about pagination but about routing. `$_GET` array is empty on every single page but the `/`. I didn't find solution yet, but you already helped me a lot. – Yevgen Mar 31 '21 at 10:33
  • No problem, if you are using a CDN have a look at it ! If not, I am really as confused as you are. – matiaslauriti Mar 31 '21 at 10:35

2 Answers2

0

Since App\Models\MyItems is a class, it should be using scope resolution ::

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

When the left part is an object instance, you use ->. Otherwise, you use ::

P. K. Tharindu
  • 2,565
  • 3
  • 17
  • 34
0

The code should be like this

$MyItems = App\Models\MyItems::paginate(10);
Basharmal
  • 1,313
  • 10
  • 30