PHP code example of amamarul / laravel-paginator
1. Go to this page and download the library: Download amamarul/laravel-paginator library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
amamarul / laravel-paginator example snippets php
Amamarul\Paginator\PaginatorServiceProvider::class,
php
use Amamarul\Paginator\Paginator;
use Illuminate\Http\Request;
public function index(Request $request)
{
$currentPage = isset($request['page']) ? (int) $request['page'] : 1;
$perPage = 1;
$path = $request->path();
$items = array_map(function ($value) {
return [
'name' => 'User #' . $value,
'url' => '/user/' . $value,
];
}, range(1,1000));
$paginator = new Paginator($items);
$paginator = $paginator->paginate($currentPage,$perPage, $path);
return view('index')->with('paginator', $paginator);
}
php
use App\User;
use Amamarul\Paginator\Paginator;
use Illuminate\Http\Request;
public function index(Request $request)
{
$currentPage = isset($request['page']) ? (int) $request['page'] : 1;
$perPage = 1;
$path = $request->path();
$items = User::with('profile')->get()->sortBy('profile.name');
$paginator = new Paginator($items);
$paginator = $paginator->paginate($currentPage,$perPage, $path);
return view('index')->with('paginator', $paginator);
}
php
@foreach ($paginator->items() as $element)
<a href="{!!$element['url']!!}"><h3>{!!$element['name']!!}</h3></a>
@endforeach
{!! $paginator->render() !!}