Pagination Implementation in Laravel-8

Pagination Implementation in Laravel-8

Pagination Implementation in Laravel-8

                             
            ?php

            namespace App\Http\Controllers\API;
            
            use App\Http\Controllers\Controller;
            use Illuminate\Http\Request;
            use App\Models\Arena;
            use Illuminate\Support\Facades\Crypt;
            use Illuminate\Support\Str;
            use Validator;
            use DB;
            use paginator;
            
            class ArenaController extends ResponseController
            {
        //Get Resources deatais--------------------------------------
        public function getArenaDetails(Request $request)
        { 
            $validator = Validator::make($request->all(), [
                'page_number' => 'required',
            ]);
            if ($validator->fails()) {
                return $this->senderror('Validation Error', $validator->errors()->first());
            }
    
            $page_limit = 10;
            $page_num = ($page_no -1)* $page_limit ;
            $total_products1  = DB::table('users')->orderBy('created_at', 'desc')->count();
            $total_pages = $total_products1 / $page_limit;
    
                if($total_pages){
                            $total_pages1 = ceil($total_pages);
                        }
    
            $arena = User::orderBy('id', 'DESC')
            ->skip($page_num)->take($page_limit)->get();
            foreach($arena as $arenaGroup)
            {
            $arenaGroup->image = $request->root().'/storage/app/public/Admin/Arena/'.$arenaGroup->image;
            }
            
    
            if(empty((count($arena) > 0))){
            return $this->senderror('[]','Invalid Arena');
            }
            else{ 
            return $this->pagination($arena,$paginate,'Arena Details Display successfully');
            }
                }
                                
                             
                         
I Hope you enjoy this blog

Thank You

Want a Team that Delivers Result ? Connect now with us.

-

Our Offices

INDIA

F-429, Phase 8B, Industrial Area, SAS Nagar, Punjab 160059

+91 82198-18163

USA

13506 Summerport Village Pky Suite 355 Windermere, FL 34786

+1 (321) 900-0079

CANADA

15 Meltwater Cres, Brampton L6P3V8

+1 (647) 892-6147