├── lang └── en │ └── pagination.php ├── config.php ├── src ├── PreviousNextTrait.php ├── LinksTrait.php ├── ServiceProvider.php └── Presenter.php ├── composer.json ├── views ├── materialize.blade.php ├── uikit.blade.php ├── bootstrap.blade.php └── foundation.blade.php └── README.md /lang/en/pagination.php: -------------------------------------------------------------------------------- 1 | '«', 6 | 'div' => '...', 7 | 'next' => '»' 8 | 9 | ); 10 | -------------------------------------------------------------------------------- /config.php: -------------------------------------------------------------------------------- 1 | 'bootstrap' 12 | ); -------------------------------------------------------------------------------- /src/PreviousNextTrait.php: -------------------------------------------------------------------------------- 1 | paginator->currentPage() <= 1) { 10 | return null; 11 | } 12 | 13 | return $this->paginator->url($this->paginator->currentPage() - 1); 14 | } 15 | 16 | protected function getNext() 17 | { 18 | if ( ! $this->paginator->hasMorePages()) { 19 | return null; 20 | } 21 | 22 | return $this->paginator->url($this->paginator->currentPage() + 1); 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /src/LinksTrait.php: -------------------------------------------------------------------------------- 1 | window['first'])) { 12 | $links = $this->window['first']; 13 | } 14 | 15 | if (is_array($this->window['slider'])) { 16 | $links += ['first_div' => ''] + $this->window['slider']; 17 | } 18 | 19 | if (is_array($this->window['last'])) { 20 | $links += ['last_div' => ''] + $this->window['last']; 21 | } 22 | 23 | return $links; 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "styde/blade-pagination", 3 | "description": "Laravel's pagination with Blade templating support", 4 | "type": "library", 5 | "keywords": ["blade","pagination"], 6 | "homepage": "http://github.com/StydeNet/blade-pagination", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Duilio Palacios", 11 | "email": "admin@styde.net", 12 | "homepage": "http://styde.net", 13 | "role": "Developer" 14 | } 15 | ], 16 | "require": { 17 | "php": ">=5.4.0", 18 | "laravel/framework": "5.*" 19 | }, 20 | "autoload": { 21 | "psr-4": { 22 | "Styde\\BladePagination\\": "src/" 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /views/materialize.blade.php: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/ServiceProvider.php: -------------------------------------------------------------------------------- 1 | loadViewsFrom(__DIR__.'/../views', 'blade-pagination'); 21 | $this->loadTranslationsFrom(__DIR__.'/../lang', 'blade-pagination'); 22 | 23 | $this->publishes([ 24 | __DIR__.'/../views' => base_path('resources/views/blade-pagination'), 25 | ]); 26 | 27 | $this->publishes([ 28 | __DIR__.'/../config.php' => config_path('blade-pagination.php'), 29 | ]); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /views/uikit.blade.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /views/bootstrap.blade.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /views/foundation.blade.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel's pagination with Blade templating support. 2 | 3 | This package is compatible with Laravel 5.0 and Laravel 5.1 4 | (but if you are using Laravel 5.0 you should update to 5.1 it takes 20 minutes or so) 5 | 6 | There is another repository to quickly try/test this package: https://github.com/StydeNet/blade-pagination-tests (it includes some automatic tests with phpunit). 7 | 8 | ## Installation 9 | 10 | To install through *Composer*: 11 | 12 | 1 - Add the following instruction to the "require" option in your composer.json: 13 | 14 | `"styde/blade-pagination": "5.1.*@dev"` and execute `composer update` in the console, inside the project's folder. 15 | 16 | Or execute `composer require styde/blade-pagination:5.1.*@dev` in the console, inside the project's folder. 17 | 18 | 2 - Add the Service Provider to the `config/app.php` file of your Laravel app: 19 | 20 | `'Styde\BladePagination\ServiceProvider'` 21 | 22 | 3 - To change the templates, please execute the following command in the console: 23 | 24 | `php artisan vendor:publish` 25 | 26 | 4 - Then you can: 27 | 28 | Change the theme (if necessary) in `config/blade-pagination.php`, example: 29 | 30 | ```php 31 | return array( 32 | 'theme' => 'bootstrap' 33 | ); 34 | ``` 35 | There are 3 available options: `bootstrap`, `foundation` and `materialize`. 36 | 37 | Change the templates in the `resources/views/blade-pagination` directory 38 | (make sure to edit or add a new template according to the theme specify in `config/blade-pagination.php`) 39 | 40 | Alternatively you can just copy the following code: 41 | 42 | ``` 43 | 'bootstrap' 54 | ); 55 | ``` 56 | 57 | ## Create themes 58 | 59 | You can create your own themes inside `resources/views/pagination`. Feel free to submit your theme via Pull Request or to `admin@styde.net`. 60 | -------------------------------------------------------------------------------- /src/Presenter.php: -------------------------------------------------------------------------------- 1 | paginator = $paginator; 22 | 23 | if ($this->hasPages()) { 24 | $this->window = is_null($window) ? UrlWindow::make($paginator) : $window->get(); 25 | } 26 | } 27 | 28 | /** 29 | * Render the given paginator. 30 | * 31 | * @return string 32 | */ 33 | public function render() 34 | { 35 | if (!$this->hasPages()) { 36 | return ''; 37 | } 38 | 39 | $data = [ 40 | 'current' => $this->paginator->currentPage(), 41 | 'previous' => $this->getPrevious(), 42 | 'links' => $this->getLinks(), 43 | 'next' => $this->getNext() 44 | ]; 45 | 46 | $theme = Config::get('blade-pagination.theme', 'bootstrap'); 47 | 48 | return $this->renderTheme($theme, $data); 49 | } 50 | 51 | /** 52 | * Determine if the underlying paginator being presented has pages to show. 53 | * 54 | * @return bool 55 | */ 56 | public function hasPages() 57 | { 58 | return $this->paginator->hasPages(); 59 | } 60 | 61 | /** 62 | * @param $theme 63 | * @param $data 64 | * @return mixed 65 | */ 66 | protected function renderTheme($theme, $data) 67 | { 68 | $customTemplate = 'blade-pagination/' . $theme; 69 | 70 | if (View::exists($customTemplate)) { 71 | return View::make($customTemplate, $data)->render(); 72 | } 73 | 74 | return View::make('blade-pagination::' . $theme, $data)->render(); 75 | } 76 | 77 | } --------------------------------------------------------------------------------