PHP code example of spatie / laravel-paginateroute
1. Go to this page and download the library: Download spatie/laravel-paginateroute 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/ */
spatie / laravel-paginateroute example snippets
// config/app.php
'providers' => [
...
'Spatie\PaginateRoute\PaginateRouteServiceProvider',
];
'aliases' => [
...
'PaginateRoute' => 'Spatie\PaginateRoute\PaginateRouteFacade',
];
// app/Providers/RouteServiceProvider.php
use PaginateRoute;
// ...
public function boot()
{
PaginateRoute::registerMacros();
parent::boot();
}
// app/Http/routes.php
// Generates /users & /users/page/{page}
Route::paginate('users', 'UsersController@index');
// app/Http/Controllers/UsersController.php
public function index()
{
return view('users.index', ['users' => \App\User::simplePaginate(5)]);
}
/**
* @param \Illuminate\Contracts\Pagination\Paginator $paginator
* @return int|null
*/
public function nextPage(Paginator $paginator)
/**
* @param \Illuminate\Contracts\Pagination\Paginator $paginator
* @return bool
*/
public function hasNextPage(Paginator $paginator)
/**
* @param \Illuminate\Contracts\Pagination\Paginator $paginator
* @return string|null
*/
public function nextPageUrl(Paginator $paginator)
/**
* @return int|null
*/
public function previousPage()
/**
* @return bool
*/
public function hasPreviousPage()
/**
* @param bool $full
* @return string|null
*/
public function previousPageUrl($full = false)
/**
* @param int $page
* @param bool $full
* @return string
*/
public function pageUrl($page, $full = false)
/**
* @param string $url
* @param int $page
* @param bool $full
* @return string
*/
public function addPageQuery($url, $page, $full = false)
/**
* @param \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator
* @param bool $full
* @return array
*/
public function allUrls(LengthAwarePaginator $paginator, $full = false)
/**
* @param \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator
* @param bool $full
* @param string $class
* @param bool $additionalLinks
* @return string
*/
public function renderPageList(LengthAwarePaginator $paginator, $full = false, $class = null, $additionalLinks = false)
/**
* @param \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator
* @param bool $full
* @return string
*/
public function renderRelLinks(LengthAwarePaginator $paginator, $full = false)
bash
$ php artisan vendor:publish --provider="Spatie\PaginateRoute\PaginateRouteServiceProvider"