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');
}
}