Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save diloabininyeri/cdc873c09b0443058614a33b9aebd71d to your computer and use it in GitHub Desktop.

Select an option

Save diloabininyeri/cdc873c09b0443058614a33b9aebd71d to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
class Deneme extends Controller
{
function index(Request $request)
{
$contact_list = [];
foreach (range(1, 100) as $i) {
$std = new \stdClass();
$std->id = $i;
$std->name = "dd" . $i;
$contact_list[] = $std;
}
$page = isset($request->page) ? $request->page : 1; // Get the page=1 from the url
$perPage = 2; // Number of items per page
$offset = ($page * $perPage) - $perPage;
$entries = new LengthAwarePaginator(
array_slice($contact_list, $offset, $perPage, true),
count($contact_list), // Total items
$perPage, // Items per page
$page, // Current page
['path' => $request->url(), 'query' => $request->query()] // We
);
return view('deneme', compact('entries'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment