Laravel 5.3 - Customizing pagination templates with example

Laravel 5.3 - Customizing pagination templates with example

In this post, i am going to tell you how to customize pagination view in Laravel 5.3.

In most of the application, pagination is very common task and Laravel PHP Framework has excellent library for pagination and with version of Laravel 5.3, you can easily customize pagination template either creating a own pagination file manually or using exist option is to run artisan command to publish the pagination template.

And this is the new feature that is added with Laravel 5.3.

As all know Laravel has default bootstrap pagination view and i here let you know :

Basic example of pagination that use default pagination view
  1. // routes file
  2. Route::get('products', function () {
  3. return view('products.index')
  4. ->with('products', Product::paginate(20));
  5. });
  1. // resource/views/products/index.blade.php
  2. @foreach ($products as $product)
  3. <!-- show the product details -->
  4. @endforeach
  5. {!! $products->links() !!}

Above example will give you simple default Laravel pagination view.

Ok, Now i will tell you how to pass custom view for Laravel pagination.

Custom Pagination Template in Laravel 5.3

If you go through publish file using php artisan command then run following command :

php artisan vendor:publish --tag=laravel-pagination

By running above command you will see the pagination directory in following path resources/views/vendor/ and in pagination directory you will get 4 files by default:

  • bootstrap-4.blade.php
  • default.blade.php
  • simple-bootstrap-4.blade.php
  • simple-default.blade.php

Laravel use default.blade.php file for default pagination view.

You can manually create your own custom pagination template and link it with pagination links method to show pagination view as per your needs.

Complete example to create a custom pagination view

First you need to create a table with some dummy data to test this code.

Step 1: Table and Model

I have created a products table(fields : name, details) in our database with some data.

Now create a model corresponding to the table:

  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Product extends Model
  5. {
  6.     public $fillable=['name','details'];
  7. }
Step2: Add route

In this step, simple add a new route for custom pagination in web.php



Step3: Create ProductController.php

In this step create a ProductController.php with index method.

  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Product;
  5. class ProductController extends Controller
  6. {
  7.     public function index(Request $request){    
  8.      $products=Product::paginate(5);
  9.      return view('products',compact('products'))->with('i', ($request->input('page', 1) - 1) * 5);
  10.     }
  11. }
Step 4: Create products.blade.php file

In this step i have created a products.blade.php in following directory resources/views/products.blade.php

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Customizing pagination templates with example in Laravel 5.3</title>
  5.     <link rel="stylesheet" type="text/css" href="">
  6. </head>
  7. <body>
  8. <div class="container">
  9.     <div class="table-responsive">
  10.      <table class="table table-bordered">
  11.      <thead>
  12.      <tr class="heading">
  13.      <th>No</th>
  14.      <th>Name</th>
  15.      <th>Details</th>
  16.      </tr>
  17.             </thead>
  18.             <tbody>
  19.              @foreach ($products as $product)
  20.                  <tr>
  21.                  <td>{{ ++$i }}</td>
  22.                  <td>{!! $product->name !!}</td>
  23.                  <td>{!! $product->details !!}</td>
  24.                  </tr>
  25.                 @endforeach
  26.             </tbody>
  27.         </table>
  28.         {!! $products->links('pagination') !!}
  29.     </div>
  30. </div>
  31. </body>
  32. </html>

In above links method, i pass the view name pagination to identify which custom template i am going to use for pagination.

Step5: create a custom template pagination.blade.php

Now in this last step we will create a template which is used by a single paginator.

  1. @if ($paginator->hasPages())
  2. <ul class="pager">
  3. {{-- Previous Page Link --}}
  4. @if ($paginator->onFirstPage())
  5. <li class="disabled"><span>? Previous</span></li>
  6. @else
  7. <li><a href="{{ $paginator->previousPageUrl() }}" rel="prev">? Previous</a></li>
  8. @endif
  9. {{-- Pagination Elements --}}
  10. @foreach ($elements as $element)
  11. {{-- "Three Dots" Separator --}}
  12. @if (is_string($element))
  13. <li class="disabled"><span>{{ $element }}</span></li>
  14. @endif
  15. {{-- Array Of Links --}}
  16. @if (is_array($element))
  17. @foreach ($element as $page => $url)
  18. @if ($page == $paginator->currentPage())
  19. <li class="active my-active"><span>{{ $page }}</span></li>
  20. @else
  21. <li><a href="{{ $url }}">{{ $page }}</a></li>
  22. @endif
  23. @endforeach
  24. @endif
  25. @endforeach
  26. {{-- Next Page Link --}}
  27. @if ($paginator->hasMorePages())
  28. <li><a href="{{ $paginator->nextPageUrl() }}" rel="next">Next ?</a></li>
  29. @else
  30. <li class="disabled"><span>Next ?</span></li>
  31. @endif
  32. </ul>
  33. @endif

Phone: (+91) 8800417876
Noida, 201301
okey metin2 pvp serverler metin2 pvp
ataşehir escort maltepe escort bostancı escort kadıköy escort maltepe escort ataşehir escort tuzla escort pendik escort ümraniye escort kartal escort
pendik escort
izmir escort izmir escort izmir escort izmir escort denizli escort antalya escort antalya escort antalya escort izmir escort izmir escort izmir escort izmir escort izmir escort
antalya escort akseki escort aksu escort alanya escort bayan antalya escort antalya grup escort antalya masöz antalya rus escort antalya sınırsız escort antalya travesti escort bdsm escort beldibi escort bayan belek escort bayan çallı escort bayan çamyuva escort bayan demre escort bayan elmalı escort bayan fethiye escort bayan finike escort bayan göynük escort bayan güllük escort bayan ışıklar escort bayan kaş escort bayan kemer escort bayan konyaaltı altınkum escort bayan konyaaltı arapsuyu escort bayan konyaaltı escort bayan konyaaltı liman escort korkuteli escort bayan kültür escort kundu escort bayan lara escort bayan manavgat escort bayan muratpaşa escort bayan örnekköy escort bayan rus escort bayan serik escort bayan side escort bayan suriyeli escort tekirova escort bayan üniversiteli escort alanya escort mahmutlar escort alanya escort mahmutlar escort alanya escort mahmutlar escort istanbul escort avrupa yakası escort şişli escort topkapı escort istanbul vip escort maslak escort merter escort aksaray escort arnavutköy escort ataköy escort bağcılar escort bahçelievler escort bakırköy escort beşitaş escort beylikdüzü escort beyoğlu escort halkalı escort istanbul sınırsız escort kağıthane escort mecidiyeköy escort nişantaşı escort escort istanbul ataşehir escort beykoz escort çekmeköy escort kadıköy escort maltepe escort pendik escort sancaktepe escort şile escort sultanbeyli escort tuzla escort ümraniye escort üsküdar escort
beylikdüzü escort istanbul escort şişli escort beylikdüzü escort istanbul escort
kocaeli escort izmit escort bayan gebze escort izmit sınırsız escort escort bursa tuzla escort aydınlı escort orhanlı escort bursa escort escort bayan istanbul escort istanbul sınırsız escort istanbul bayan escort izmit escort izmit escort kocaeli escort sisli escort mecidiyekoy escort bursa escort bayan bursa görükle escort maltepe escort goztepe escort yakacik-yeni-escort bursa sınırsız escort sisli escort bayan taksim escort bursa escort porno izle sikiş izle atasehir escort antalya escort
ankara escort marmaris escort bursa escort mersin escort antalya escort izmir escort samsun escort bodrum escort çeşme escort kuşadası escort adana escort eskişehir escort gaziantep escort esenyurt escort pendik escort tuzla escort fatih escort ümraniye escort mecidiyeköy escort kartal escort bahçelievler escort bahçeşehir escort ataşehir escort bakırköy escort nişantaşı escort avcılar escort büyükçekmece escort kurtkoy escort konya escort beşiktaş escort taksim escort beylikdüzü escort malatya escort sakarya escort şişli escort maltepe escort kadıköy escort ataköy escort bostancı escort şirinevler escort bağcılar escort üsküdar escort etiler escort başaksehir escort ortaköy escort kağıthane escort sultangazi escort halkalı escort çekmeköy escort şaşkınbakkal escort mamak escort sincan escort keçiören escort çankaya escort beypazarı escort akyurt escort pursaklar escort kahramankazan escort göztepe escort alsancak escort bornova escort buca escort karabaglar escort karşıyaka escort konak escort narlıdere escort izmit escort başiskele escort kandira escort körfez escort karamürsel escort dilovası escort gölcük escort gebze escort kocaeli escort kayseri escort elazığ escort denizli escort diyarbakir escort adana escort ankara escort izmir escort antalya escort gaziantep escort kayseri escort konya escort mersin escort denizli escort kocaeli escort diyarbakır escort alanya escort manavgat escort bursa escort eskişehir escort sakarya escort samsun escort malatya escort trabzon escort adıyaman escort afyon escort ağrı escort aksaray escort amasya escort ardahan escort artvin escort aydın escort balikesir escort bartın escort batman escort bayburt escort bilecik escort bingöl escort bitlis escort bolu escort burdur escort çanakkale escort çankırı escort çorum escort düzce escort edirne escort elazığ escort erzincan escort erzurum escort giresun escort gümüşhane escort hatay escort ığdır escort ısparta escort maraş escort karabük escort karaman escort kars escort kastamonu escort kilis escort kırıkkale escort kırklareli escort kırşehir escort kütahya escort manisa escort mardin escort muğla escort muş escort nevşehir escort niğde escort ordu escort osmaniye escort rize escort urfa escort siirt escort sinop escort şırnak escort sivas escort ordu escort tokat escort tunceli escort usak escort van escort yalova escort yozgat escort zonguldak escort kıbrıs escort
adana escort ankara escort bursa escort diyarbakir escort eskisehir escort kayseri escort kocaeli escort konya escort malatya escort maras escort mersin escort ordu escort sakarya escort samsun escort hatay escort mardin escort tekirdag escort antalya escort aydin escort nigde escort nevsehir escort elazig escort manisa escort osmaniye escort denizli escort mugla escort
bedava bahis
ankara escort - ankara escort
ataşehir escort ataşehir anadolu yakası escort ankara escort antalya escort antalya escort

flynta 5 mg

flynta 5 mg fiyat

orcafil 5 mg




combo 100 mg

degra 100 mg




lifta 20

vigrande 100 mg

lifta 20 mg

lifta 5 mg

sildegra 100 mg


flynta 20 mg

viagra 100 mg fiyat

orijinal viagra

viagra 100 mg

eczane viagra

viagra sipariş

viagra satın al

viagra nedir

viagra yorum

viagra fiyat

viagra fiyatı 2021


cialis fiyat

cialis 20 mg

cialis 100 mg

cialis nedir

cialis 5 mg fiyatı

cialis hap

cialis 5 mg

cialis 20 mg eczane fiyatı

cialis 100 mg fiyat

cialis satış

izmir escort
ataşehir escort
pendik aktar