Does anyone have any idea how to create a pagination with RESTFULL API in Laravel?

Asked

Viewed 522 times

1

Could someone give me an example of how to do this and JQUERY build paging? Even if it’s some tutorial. I have already searched several places and all say the same thing to create a pagination in the proper Windows and bring in a view. Only my problem is to bring this paging with JQUERY in another project, via API in JSON. Could someone explain it to me and give an example?

  • 1

    can explain better what you want?

1 answer

0

I think the answer is simple: Use the method paginate of Laravel.

I always use this in my applications to make a "paging" (actually what I do is a load on demand, using Laravel’s paging logic).

What you need to understand is that Laravel paging works by passing the parameter page in the url query.

That is to say:

Route::get('/api/users', function () {
     return User::paginate(10); // vai exibir de 10 em 10
});

In jQuery, you make your logic for parameter page be added dynamically:

var page = 1;

$.get('/api/users?page=' + page, function (response) {

});

If you change the value of pagefor 2, you would notice that the "next page" would be loaded with the data you need. Knowing this, you can apply your logic freely.

Generally, what I usually do is an implementation with Angular and Inifinite Scroll.

I have a library where you can get more examples.

  • Dude I tried to do but I need the page to be automatic understood?

  • I’ll put my code in the question

  • 1

    But the logic of the page is you who will implement. Your question is not clear in the sense of how it will implement.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.