Skip to content

Instantly share code, notes, and snippets.

@diloabininyeri
Created October 25, 2019 11:26
Show Gist options
  • Save diloabininyeri/f92d350bae637dec622dd61f01913f62 to your computer and use it in GitHub Desktop.
Save diloabininyeri/f92d350bae637dec622dd61f01913f62 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers;
use App\Paginator;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
class Deneme extends Controller
{
function index(Request $request)
{
$data=[];
foreach (range(1,50) as $i)
{
$std=new \stdClass();
$std->id=$i;
$data[]=$std;
}
$collect = collect($data);
$currentPage = LengthAwarePaginator::resolveCurrentPage();
$itemCollection = collect($collect);
$perPage = 10;
$currentPageItems = $itemCollection->slice(($currentPage * $perPage) - $perPage, $perPage)->all();
$paginatedItems= new LengthAwarePaginator($currentPageItems , count($itemCollection), $perPage);
$paginatedItems->setPath($request->url());
return view('deneme',['items' => $paginatedItems]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment