'Create laravel api with page and limit results
I want to create an api with limit and page number, I am trying to use the api to load more data on scroll in my app.
Question 1: How can I limit the result, per each page.
For example
https://placewave.com/allusers?results=10&page=2
The URL above the page=2 show the second page with results=10 10 fetch result for page 2, same thing for page 3 with 10 result.
My Code
public function allUser(Request $request)
{
$pageno = $request->pageno;
return Users::where('active', 'online')
->limit(10)->offset($pageno)
->get();
}
Solution 1:[1]
->paginate($request->get('results', 10))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Hicham AIT TALGHALIT |
