Readouble

Laravel 4.2 Pagination

Configuration

In other frameworks, pagination can be very painful. Laravel makes it a breeze. There is a single configuration option in the app/config/view.php file. The pagination option specifies which view should be used to create pagination links. By default, Laravel includes two views.

The pagination::slider view will show an intelligent "range" of links based on the current page, while the pagination::simple view will simply show "previous" and "next" buttons. Both views are compatible with Twitter Bootstrap out of the box.

Usage

There are several ways to paginate items. The simplest is by using the paginate method on the query builder or an Eloquent model.

Paginating Database Results

$users = DB::table('users')->paginate(15);

Note: Currently, pagination operations that use a groupBy statement cannot be executed efficiently by Laravel. If you need to use a groupBy with a paginated result set, it is recommended that you query the database manually and use Paginator::make.

Paginating An Eloquent Model

You may also paginate Eloquent models:

$allUsers = User::paginate(15);

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

The argument passed to the paginate method is the number of items you wish to display per page. Once you have retrieved the results, you may display them on your view, and create the pagination links using the links method:

<div class="container">
	<?php foreach ($users as $user): ?>
		<?php echo $user->name; ?>
	<?php endforeach; ?>
</div>

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

This is all it takes to create a pagination system! Note that we did not have to inform the framework of the current page. Laravel will determine this for you automatically.

If you would like to specify a custom view to use for pagination, you may pass a view to the links method:

<?php echo $users->links('view.name'); ?>

You may also access additional pagination information via the following methods:

  • getCurrentPage
  • getLastPage
  • getPerPage
  • getTotal
  • getFrom
  • getTo
  • count

"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);

Creating A Paginator Manually

Sometimes you may wish to create a pagination instance manually, passing it an array of items. You may do so using the Paginator::make method:

$paginator = Paginator::make($items, $totalItems, $perPage);

Customizing The Paginator URI

You may also customize the URI used by the paginator via the setBaseUrl method:

$users = User::paginate();

$users->setBaseUrl('custom/url');

The example above will create URLs like the following: http://example.com/custom/url?page=2

Appending To Pagination Links

You can add to the query string of pagination links using the appends method on the Paginator:

<?php echo $users->appends(array('sort' => 'votes'))->links(); ?>

This will generate URLs that look something like this:

http://example.com/something?page=2&sort=votes

If you wish to append a "hash fragment" to the paginator's URLs, you may use the fragment method:

<?php echo $users->fragment('foo')->links(); ?>

This method call will generate URLs that look something like this:

http://example.com/something?page=2#foo

Converting To JSON

The Paginator class implements the Illuminate\Support\Contracts\JsonableInterface contract and exposes the toJson method. You may also convert a Paginator instance to JSON by returning it from a route. The JSON'd form of the instance will include some "meta" information such as total, current_page, last_page, from, and to. The instance's data will be available via the data key in the JSON array.

Custom Presenters

The default pagination presenter is Bootstrap compatible out of the box; however, you may customize this with a presenter of your choice.

Extending The Abstract Presenter

Extend the Illuminate\Pagination\Presenter class and implement its abstract methods. An example presenter for Zurb Foundation might look like this:

class ZurbPresenter extends Illuminate\Pagination\Presenter {

    public function getActivePageWrapper($text)
    {
        return '<li class="current"><a href="">'.$text.'</a></li>';
    }

    public function getDisabledTextWrapper($text)
    {
        return '<li class="unavailable"><a href="">'.$text.'</a></li>';
    }

    public function getPageLinkWrapper($url, $page, $rel = null)
    {
        return '<li><a href="'.$url.'">'.$page.'</a></li>';
    }

}

Using The Custom Presenter

First, create a view in your app/views directory that will serve as your custom presenter. Then, replace pagination option in the app/config/view.php configuration file with the new view's name. Finally, the following code would be placed in your custom presenter view:

<ul class="pagination">
    <?php echo with(new ZurbPresenter($paginator))->render(); ?>
</ul>

章選択

Artisan CLI

設定

明暗テーマ
light_mode
dark_mode
brightness_auto システム設定に合わせる
テーマ選択
photo_size_select_actual デフォルト
photo_size_select_actual モノクローム(白黒)
photo_size_select_actual Solarized風
photo_size_select_actual GitHub風(青ベース)
photo_size_select_actual Viva(黄緑ベース)
photo_size_select_actual Happy(紫ベース)
photo_size_select_actual Mint(緑ベース)
コードハイライトテーマ選択

明暗テーマごとに、コードハイライトのテーマを指定できます。

テーマ配色確認
スクリーン表示幅
640px
80%
90%
100%

768px以上の幅があるときのドキュメント部分表示幅です。

インデント
無し
1rem
2rem
3rem
原文確認
原文を全行表示
原文を一行ずつ表示
使用しない

※ 段落末のEボタンへカーソルオンで原文をPopupします。

Diff表示形式
色分けのみで区別
行頭の±で区別
削除線と追記で区別

※ [tl!…]形式の挿入削除行の表示形式です。

テストコード表示
両コード表示
Pestのみ表示
PHPUnitのみ表示
OS表示
全OS表示
macOSのみ表示
windowsのみ表示
linuxのみ表示
和文変換

対象文字列と置換文字列を半角スペースで区切ってください。(最大5組各10文字まで)

本文フォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

コードフォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

保存内容リセット

localStrageに保存してある設定項目をすべて削除し、デフォルト状態へ戻します。

ヘッダー項目移動

キーボード操作