laravel show only next and previous link in pagination

…衆ロ難τιáo~ 提交于 2019-12-10 16:33:39

问题


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


回答1:


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',



回答2:


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:

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:




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/26148645/laravel-show-only-next-and-previous-link-in-pagination

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!