Saturday, February 20, 2016

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.

$presenter = new Illuminate\Pagination\BootstrapPresenter($paginator);

<?php if ($paginator->getLastPage() > 1): ?>
    <ul class="pagination">
        <?php echo $presenter->render(); ?>
            echo Form::open(array('url' => $paginator->getUrl(0), 'method' => 'GET'));
            <?php echo Form::close(); ?>
<?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.

No comments:

Post a Comment