Does anyone have any idea how to create a page with RESTFULL API in Laravel? [closed]

1

Could someone give me an example of how to do this and JQUERY mount the paging? Even if it's some tutorial. I have already researched in several places and they all say the same thing to create a pagination in the laravel itself and bring in a view. But my problem is to bring this pagination with JQUERY in another project, via API in JSON. Could someone explain and give me an example?

    
asked by anonymous 16.10.2017 / 18:03

1 answer

0

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

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

What you need to understand is that the laravel pagination works by passing the page parameter to the url query.

That is:

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

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

var page = 1;

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

});

If you change the value from page to 2 , you would notice that the "next page" would load 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.

    
17.10.2017 / 13:23