Readouble

Laravel 5.dev ペジネーション

設定Configuration

他のフレームワークのペジネーションは苦痛に満ちています。Laravelはこれを簡単にしてくれます。Laravelは現在のページ位置に基づいて、賢い「ページ範囲」のリンクを生成します。生成されるHTMLはBootstrap CSSフレームワークへ適合しています。In other frameworks, pagination can be very painful. Laravel makes it a breeze. Laravel can generate an intelligent "range" of links based on the current page. The generated HTML is compatible with the Bootstrap CSS framework.

使用法Usage

アイテムをページ分けするには多くの方法があります。一番シンプルな方法はEloquentモデルかクエリービルダーに、paginateメソッドを用いることです。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);

注意: 現在、groupByメソッドを使用したペジネーション操作は、Laravelで正しく実行できません。groupByを使用したペジネーションを使用する必要がある場合は、データベースクエリーを実行し、その結果でPaginator::makeを使用することをおすすめします。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.

EloquentモデルをペジネーションするPaginating An Eloquent Model

さらにEloquentモデルもペジネーションできます。You may also paginate Eloquent[/docs/master/eloquent] models:

$allUsers = User::paginate(15);

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

paginateメソッドに渡している引数は表示したいアイテムの個数です。一度結果を受け取ったら、それをビューで表示してください。それからrenderメソッドを使ってペジネーションリンクを生成してください。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 render method:

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

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

これらの生成は全部ペジネーションシステムが面倒を見ます。フレームワークに現在ページを指定していないことに注意してください。Laravelは自動的に判断します。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.

さらに、以下のメソッドを使用し、追加のペジネーション情報にアクセスできます。You may also access additional pagination information via the following methods:

  • currentPagecurrentPage
  • lastPagelastPage
  • perPageperPage
  • totaltotal
  • countcount

シンプル・ペジネーション"Simple Pagination"

「次」と「前」のリンクだけをペジネーションビューに表示したい場合は、simplePaginateメソッドを使用する選択肢により、より効率的にクエリーすべきでしょう。これは、ビューに正確なページ番号を表示する必要がない、巨大なデータセットに対して便利です。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

時にはアイテムを配列で渡し、手動でペジネーションインスタンスを生成したい場合もあるでしょう。必要に応じ、Illuminate\Pagination\PaginatorIlluminate\Pagination\LengthAwarePaginatorインスタンスのどちらかを生成することで、可能です。Sometimes you may wish to create a pagination instance manually, passing it an array of items. You may do so by creating either an Illuminate\Pagination\Paginator or Illuminate\Pagination\LengthAwarePaginator instance, depending on your needs.

ペジネーターでカスタムURIを使用するCustomizing The Paginator URI

ペジネーターにより使用されるURIも、setPathメソッドでカスタマイズできます。You may also customize the URI used by the paginator via the setPath method:

$users = User::paginate();

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

上の例では、次のURLリンクが生成されます。http://example.com/custom/url?page=2The example above will create URLs like the following: http://example.com/custom/url?page=2[http://example.com/custom/url?page=2]

ペジネーションリンクの追加Appending To Pagination Links

ペジネーターのappendsメソッドを使用しペジネーションリンクのクエリー文字列を追加することができます。You can add to the query string of pagination links using the appends method on the Paginator:

<?php echo $users->appends(['sort' => 'votes'])->render(); ?>

この例で、以下のようなURLが生成されます。This will generate URLs that look something like this:

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

ペジネーションのURLに「ハッシュフラグメント」を追加したい場合は、fragmentメソッドが使用できます。If you wish to append a "hash fragment" to the paginator's URLs, you may use the fragment method:

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

このメソッドの呼び出しで、次のようなURLが表示されます。This method call will generate URLs that look something like this:

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

JSONへ変換するConverting To JSON

Paginatorクラスは、Illuminate\Contracts\Support\JsonableInterface契約を実装しており、toJsonメソッドを備えています。Paginatorインスタンスをルートから返すことにより、JSONに変換することもできます。インスタンスのJSON形式には、totalcurrent_pagelast_pageのような「メタ」情報が含まれています。インスタンスのデーターは、JSON配列のdataキーにより利用できます。The Paginator class implements the Illuminate\Contracts\Support\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, and last_page. The instance's data will be available via the data key in the JSON array.

章選択

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のみ表示
和文変換

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

本文フォント

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

コードフォント

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

保存内容リセット

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

ヘッダー項目移動

キーボード操作