Several minutes ago my friend ask me about how to create custom pagination with Laravel 5. This is interesting. I’ve never tried create custom pagination on Laravel 5. On Laravel 4, that’s easy. Just change the app/config/view.php with your implementation, and you are done.

By the way, he is a Python programmer. I don’t know what is he doing with Laravel 😕

After seconds looking the source code, Whoaa that’s very easy.

For quick demo, I just put the presenter on app/Http/routes.php file.


class CustomPresenter implements Illuminate\Contracts\Pagination\Presenter
    public function render()
        return 'Alpha and Omega';

    public function hasPages()
        // do something here

Route::get('/', function()
    $items = range('a', 'z'); // will create a, b, c, ..., z

    $paginatedItems = new Illuminate\Pagination\Paginator($items, 10);

    return view('welcome', compact('paginatedItems'));

And add this to the view resources/views/welcome.blade.php

{!! $paginatedItems->render(new CustomPresenter) !!}

And we are done. 😜

Maybe I will add the part two of this post.


Tinggalkan Balasan

Please log in using one of these methods to post your comment:


You are commenting using your account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s