Search
 
SCRIPT & CODE EXAMPLE
 

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(),
            ],
        ]);
Comment

laravel api pagination automatically get request

$users = User::paginate($request->get('perPage')); 
$users->appends($request->all());
Comment

pagination in api laravel

follow this link 
https://github.com/spatie/laravel-json-api-paginate
Comment

Paginating API HTTP Response in Laravel

 public function paginate ($items, $perPage =4,  $page = null) {
        $page = $page ?: (LengthAwarePaginator::resolveCurrentPage() ?:1);
            $total = count($items);
            $currentpage =$page;
            $offset = ($currentpage * $perPage) - $perPage;
            $itemstoshow =array_slice($items, $offset, $perPage);
        return new LengthAwarePaginator($itemstoshow, $total, $perPage);
    }

public function fetch() {
//connect to api
$collection= Http::get('192.168.1.19/EnwealthWebAPi/ke/enwealth/contributions?memberNo=KEMI-002&company=KEMI%20SRBS')->json();     
// return view('test', ['collection' =>$collection['value']]);
return view('test', ['collection' =>$collection['value']]-paginate(20));
}

Comment

PREVIOUS NEXT
Code Example
Php :: how to execute php in linux 
Php :: eloquent relationships 
Php :: php numeric array 
Php :: laravel set middleware default 
Php :: laravel send data with a redirect 
Php :: laravel 8 cron job 
Php :: php interview questions for experience 
Php :: php array_push 
Php :: Laravel DB facade relations 
Php :: php leggere file txt riga per riga 
Php :: laravel htaccess to remove public from url 
Php :: wherenotnull laravel 
Php :: pegar porcentagem de um valor php 
Php :: restrict_manage_posts hook 
Php :: Remove Version from CSS and JS 
Php :: How to post a mutlipart file using file_get_contents in php 
Php :: wordpress php 
Php :: breaks the collection into multiple smaller collections Laravel 
Php :: php array associatif move element 
Php :: phpexcel set data type 
Php :: laravel 7 link to another page with language prefix 
Php :: rename image file using post id in wordpress programmatically 
Php :: How to hide tax details from woocommerce order emails 
Php :: how to create php message 00 
Php :: get_user_info 
Php :: cout post on category in controller laravel 
Php :: typo3 add backend skin 
Php :: php check if cli mode 
Php :: edit order of columns for wordpress 
Php :: WP DELETE UNUSED TAGS 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =