Skip to content

Commit 0567c0b

Browse files
author
ahmadhuss
committed
feat: Added Pagination functionality for the ProductsAPI
1 parent a2ac37b commit 0567c0b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

app/Http/Controllers/Api/ProductController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ class ProductController extends Controller
1212
// We want category object also so that's why we have created the relationship
1313
// So our query will be use `with()` which help us to return the relationship too.
1414
public function index() {
15-
$products = Product::with('category')->get();
15+
/**
16+
* In Traditional way we use this approach to generate pagination links.
17+
* $products = Product::with('category')->paginate(9);
18+
* After that we use interpolate syntax in blade file to render pagination links. { $products->link }
19+
* API approach is similar to like this one.
20+
*/
21+
$products = Product::with('category')->paginate(9);
1622
// return $products;
1723
return ProductResource::collection($products);
1824
}

0 commit comments

Comments
 (0)