6

I ma trying to use Laravel Pagination and I only want to show the Previous and Next link with out the number 1 2 3 ...

how could I do that? I followed Laravel page : "Simple Pagination"

If you are only showing "Next" and "Previous" links in your pagination view, you have the option of using the simplePaginate method to perform a more efficient query. This is useful for larger datasets when you do not require the display of exact page numbers on your view:

$someUsers = User::where('votes', '>', 100)->simplePaginate(15);

but this still shows the page number when I do this in my view:

<?php echo $someUsers->links(); ?>

can anyone help

Thanks

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
user3150060
  • 1,725
  • 7
  • 26
  • 46
  • 1
    All the answers here give you piece of info, however none answers how to do what you ask for **inline** - so check my answer for details. – Jarek Tkaczyk Oct 02 '14 at 08:37
  • if someone looking for how to customize pagination in Laravel 5.3 check out https://stackoverflow.com/questions/28240777/custom-pagination-view-in-laravel-5/44845954#44845954 – Joyal Jul 02 '17 at 06:23

5 Answers5

16

tldr; you want to use simplePaginate() method on the query AND links('some.view') on the paginator (in the view) in order to achieve what you ask for.

Here's what you need in order to show chosen links in given template:

// inline choose simple links (prev, next)
{{ $someUsers->links('pagination::simple') }}

// inline choose slider links
{{ $someUsers->links('pagination::slider') }}

// inline choose slider-3 (default)
{{ $someUsers->links('pagination::slider-3') }}

These are framework's templates, placed in laravels directory: Illuminate/Pagination/views/

You can always decide to use your custom templates, for this simply call:

// assuming you have it in app/views/pagination/my-links.blade.php
{{ $someUsers->links('pagination.my-links') }}

// or using views namespace (you need to define it first)
{{ $someUsers->links('myNamespace::my-links') }}

Of course you can define your links as default in app/config/view.php:

// instead of
'pagination' => 'pagination::slider-3',

// something like
'pagination' => 'pagination.my-links',
Jarek Tkaczyk
  • 78,987
  • 25
  • 159
  • 157
5

You need to use:

$someUsers = User::where('votes', '>', 100)->simplePaginate(15);

as you used

and in app/config/view.php you need to set pagination to pagination::simple (by default it's set to pagination::slider-3). Then you'll have by default pagination as in the image:

Simple pagination in Laravel

You can also set custom text for previous and next items editing file lang/en/pagination.php (for other language of course you need to change it in other lang directory). By default it's set to:

'previous' => '&laquo; Previous',

'next'     => 'Next &raquo;',

but you can change it to:

'previous' => '&laquo;',

'next'     => '&raquo;',

and then it will look like as in the image:

Simple pagination in Laravel  - arrows only

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291
5

I tried this and it's working with me :

{{$someUsers->links('pagination::bootstrap-4')}}
Abd Abughazaleh
  • 4,615
  • 3
  • 44
  • 53
2

In config/view.php:

/*
|--------------------------------------------------------------------------
| Pagination View
|--------------------------------------------------------------------------
|
| This view will be used to render the pagination link output, and can
| be easily customized here to show any view you like. A clean view
| compatible with Twitter's Bootstrap is given to you by default.
|
*/

'pagination' => 'pagination::slider-3',

Set this to simple.

Source: http://youtu.be/lIEcyOUcNQk?t=8m00s

Thomas Jensen
  • 2,138
  • 2
  • 25
  • 48
  • will that change all of them or I can still use simplePaginate and paginate() methods? – user3150060 Oct 01 '14 at 19:07
  • Sure you don't have an environment version of this file with different content? – Thomas Jensen Oct 01 '14 at 19:13
  • i changed it to simple now it works , but now all my pagination shows with only previous and next , can i have some with pages and some without pages? – user3150060 Oct 01 '14 at 19:14
  • According to the documentation (http://laravel.com/docs/4.2/pagination) by applying `->simplePaginate(15);` as you have tried. Sure you are not caching the results or updating the wrong line? – Thomas Jensen Oct 01 '14 at 19:18
  • One more thing you should try, clear your `app/storage/view` folder and browser cache. – Thomas Jensen Oct 01 '14 at 19:19
  • it worked now but can I mix it , so sometimes i use with number and others without? – user3150060 Oct 01 '14 at 19:20
  • for me now if I use simplePaginate(15) or paginate(15) they have the same result with Previous and Next link? isnt that suppose to be different? – user3150060 Oct 01 '14 at 19:22
  • You have Previous and Next because of your setting in `view.php`, change that back to `pagination::slider-3`, use `simplePaginate(15)` and clear your `app/storage/view` folder as I suggested. – Thomas Jensen Oct 01 '14 at 19:24
  • yes i did like you said , now my pagination got page number like : 1 2 3 etc and it doesnt really matter if I use simplePaginate(15) or paginate(15) I stil get it with number 1 , 2 3 etc.. , and thats with view.php, go this setting: pagination::slider-3 but thats not what I want I want to use both on different page like one page got numbers of pages otehr got only Previous and Next is that Possible? – user3150060 Oct 01 '14 at 19:29
2

See the very bottom of this manual page to see how to implement a custom view for the pagination. Summarizing, you need to follow these steps:

  1. Create a view for the paginator somewhere in app/views.
  2. Replace the pagination option in app/config/views.php with the path Laravel will use to locate your new view.
  3. Display your custom paginatation view in your view like this:

    <?php echo with(new ZurbPresenter($paginator))->render(); ?>
    

Where ZurbPresenter is the class name of your pagination presenter.

Jeff Lambert
  • 24,395
  • 4
  • 69
  • 96
  • 1
    why do I need a custom pagination , read laravel manual here : http://laravel.com/docs/4.2/pagination under 'Simple Pagination" , why its showing other pages number? – user3150060 Oct 01 '14 at 19:10