alihuseyin's avatar

laravel ajax pagination

Hello, I dont know much about ajax, just started today. I tried this example https://hdtuto.com/article/laravel-55-ajax-pagination-example and it works fine but i want to a fixed url that does not include pagination numbers. eg:

mysite.com/categories?page=4  // i dont want this 
mysite.com/categories         // i want this

Can you suggest me any way or tutorial?

0 likes
5 replies
click's avatar

The real question is: why?

Why don't you want the ?page=4 in the url?

Doing a POST request to retrieve data seems (is) wrong. You should just use a GET request because that is what you are doing: retrieve data.

I would recommend you follow the REST principle for your routes:

  • GET: /categories (retrieve all categories, optionally paginated)
  • POST: /categories (add a new category)
  • PUT: /categories/{category} (update a category)
  • DELETE /categories/{category} delete a category)
cmdobueno's avatar

@m-rk

I agree with you 100%. Was just giving him a way to get what he wants... but yes it seems totally pointless and the user will not directly see this pagination link... nor does it actually impact anything they are doing at all...

alihuseyin's avatar

@m-rk , Thanks for your answer, Maybe i am doing wrong from the begging so there is a good question from you - why?- I am doing something like a quiz system so i dont want usuers to change url, they will only see next question (or anything). Maybe i should not use pagination system?

click's avatar

@alihuseyin even if you use POST in that case the user is still able to change the page. You need some other implementation to prevent users going to pages/steps they are not allowed to visit (yet).

If you are making a quiz with steps (or call it pages) you should keep track of the user progress. You could do this with sessions or storing it in the database. Than you are able to check if the user is allowed to be at step 1, step 2, step 3, etc.

There are multiple implementations possible here. It depends on what you want and what the restrictions are. Do you have authorized in users that are taking the quiz or are there only unauthorized users? Can users take multiple tests? Can they go steps back and forth? etc. etc.

Please or to participate in this conversation.