mayoz/pagination is a Laravel package for beautiful urls for laravel pagination.
It currently has 10 GitHub stars and 97 downloads on Packagist.
Install it with composer require mayoz/pagination.
Discover more Laravel packages by mayoz
or browse all Laravel packages to compare alternatives.
Last updated
Create beautiful and SEO friendly links for pagination.
First, you'll need to add the package to the require attribute of your composer.json file:
{
"require": {
"mayoz/pagination": "dev-master"
},
}
Afterwards, run composer update from your command line.
And finaly, open config/app.php. Find 'Illuminate\Pagination\PaginationServiceProvider' and replace with 'Mayoz\Pagination\PaginationServiceProvider' in providers array.
This is very easy. Consider the following examples. I accept to have your model. Create route, controller and view.
Define route in app\Http\routes;
<?php
$router->get('articles/{page?}', [
'as' => 'articles',
'uses' => 'HomeController@articles'
]);
Cool. Don't write extra code!
<?php namespace App\Http\Controllers;
use App\Article;
class HomeController {
public function articles()
{
$articles = Article::paginate(5);
return view('articles', compact('articles'));
}
}
Core pagination class not changed. Can use all the features offered by Laravel.
<ul>
@foreach ($articles as $article)
<li>{{ $article->title }}<li>
@endforeach
</ul>
{!! $articles->links() !!}
You also use;
{!! $articles->appends([ 'sort' => 'vote' ])->links() !!}{!! $articles->links('pagination.special') !!}The following outputs are generated. I think that's enough examples. As possible, SEO friendly. Nevertheless, please check your url. Use canonical metadata if necessary.
Use such as {page?}, if page pattern at the end of the route.
<?php
$router->get('articles/{page?}', [
'as' => 'articles',
'uses' => 'HomeController@articles'
]);
Outputs:
If {page} pattern in the middle of the route, no need to question mark.
<?php
$router->get('module/{page}/articles', [
'as' => 'module.articles',
'uses' => 'HomeController@articles'
]);
Outputs:
If you need to use another route instead of the current route, use the route() method. This method accepts the route name and route arguments.
NOTE: Second arg is optional. This arg for special routes parameters.
Routes is different but used same controller and view.
<?php
$router->get('articles', [
'as' => 'articles',
'uses' => 'HomeController@articles'
]);
$router->get('articles/{module}/{page?}', [
'as' => 'articles.paginate',
'uses' => 'HomeController@articles'
]);
The same as the previous definition. Added special route (its name article.paginate) for pagination url builder. This route required one parameter (module) except {page}.
NOTE: Set automatically route parameters on current route.
<?php namespace App\Http\Controllers;
use App\Article;
class HomeController {
public function articles()
{
$articles = Article::paginate(5);
$articles->route('articles.paginate', [ 'module' => 'photo' ]);
return view('articles', compact('articles'));
}
}
Outputs:
Install and use this package. If find bug, fix and send a pull request on the develop branch.
This package was written by Sercan Çakır. It released under the MIT License. See the LICENSE file for details.