Level 29
To paginate item, you can just
$products = Product::paginate(12);
return view('products.index',compact($products));
Refer https://laravel.com/docs/7.x/pagination#paginating-eloquent-results.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I want to make an API endpoint which gets all products with paginate 12 as well as the max and min price of the products. Desired output is something like:
{
"data": [
{
"id": 1,
"category_id": 1,
"name": "et",
"description": "Est aut temporibus cum voluptatem et eos. Sint repudiandae est quo quia nihil aliquid. Quae ipsam cupiditate explicabo adipisci.",
"price": "2.08",
"category": {
"id": 1,
"name": "id",
"product_count": null,
"url": "https://learnapi.test"
}
// 11 more products
}
],
"links": {
"first": "http://learnapi.test/api/products?page=1",
"last": "http://learnapi.test/api/products?page=100",
"prev": null,
"next": "http://learnapi.test/api/products?page=2"
},
"meta": {
"current_page": 1,
"from": 1,
"last_page": 100,
"path": "http://learnapi.test/api/products",
"per_page": 1,
"to": 1,
"total": 100,
}
"max_price": 1000,
"min_price": 20
}
How can I do this?
Please or to participate in this conversation.