Have you seen this: https://medium.com/@rafaelogic/create-a-vuetiful-infinite-scroll-8913a069a201
Sep 8, 2019
8
Level 11
Pagination on a Laravel Resource?
How to paginate this with Ajax? This is my Posts API which is consumed by my front-end (in Vue/Nuxt). I am trying to implement an infinite scroll but ->paginate(5) (commented out) does not work.
class PostsApiController extends Controller
{
use MediaUploadingTrait;
public function index()
{
return new PostResource(
Post::where([
['status', '=', 'published'],
])
->select('id', 'title', 'slug')
//->take(3)
//->paginate(5)
->get()
);
}
}
Level 11
Figured it out: Turns out you cant use get() and paginate() together here. The paginate() works fine without the get()
class PostsApiController extends Controller
{
use MediaUploadingTrait;
public function index()
{
return new PostResource(
Post::where([
['status', '=', 'published'],
])
->select('id', 'title', 'slug')
//->take(3)
->paginate(5)
);
}
}
Please or to participate in this conversation.