Laravel 4.2 Using Custom View for Pagination

Recently in one of my project we used laravel pagination and we have to use custom pagination as the theme we used were having different CSS classes for pagination which were not compatible with laravel default views. So in this blog I am going to explain how to do this. 

First of all open app/config/view.php file. Here remove pagination key and add following key. 
‘pagination’ => ‘paging’
Now go to your views folder and add new file and name it paging.blade.php and add following content to it.
<?php
$presenter = new IlluminatePaginationBootstrapPresenter($paginator);
?>
<?php if ($paginator->getLastPage() > 1): ?>
    <ul class=”pagination”>
        <?php echo $presenter->render(); ?>
        <li>
            <?php
            echo Form::open(array(‘url’ => $paginator->getUrl(0), ‘method’ => ‘GET’));
            ?>
            <?php echo Form::close(); ?>
        </li>
    </ul>
<?php endif; ?>
Above is your custom view so you can make changes as per your requirements and add custom code. 
Now add following code where you want to display paging. First of all in controller file. 
$pagedData = Model::where(‘company_id’,$companyId)->paginate(5);
Now in view add following code.
{{ $pagedData->links(); }}
That’s it now you have custom paging view in your laravel app.
This entry was posted in CSS, HTML5, Laravel on by .

About Hiren Dave

Hiren Dave is a software engineer, blogger and consultant with over 9 years of professional experience. He writes code in number of languages. Hiren has a passion for developing web apps, mobile apps and writing books and blog articles about programming. He has a solid experience of startups as he manages products for few startups. He is also passionate about researching and learning new technologies and trends. He has also authored a book Instant Sencha Touch, published by Packt and creator of Video Course "Beginning Laravel" for Packt

Leave a Reply

Your email address will not be published. Required fields are marked *