Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

best pagination in laravel api with eloquent

#Best Pagination for Api's in laravel using eloquent
$billerCategories = BillerCategory::select('id', 'name', 'sp_key', 'category_order', 'sp_name', 'api_id', 'address_flag')->paginate(10);
 
 return Ipay::response([
       'statusCode' => 'TXN',
       'status' => 'Biller categories fetched successfully',
          'data' => [
              'meta' => [
                    'totalPages' => $billerCategories->lastPage(),
                    'currentPage' => $billerCategories->currentPage(),
                    'totalRecords' => $billerCategories->total(),
                    'recordsOnCurrentPage' => $billerCategories->count(),
                    'recordFrom' => $billerCategories->firstItem(),
                    'recordTo' => $billerCategories->lastItem(),
                ],
                'records' => $billerCategories->items(),
            ],
        ]);
 
PREVIOUS NEXT
Tagged: #pagination #laravel #api #eloquent
ADD COMMENT
Topic
Name
8+9 =