LoginSignup
0
0

More than 3 years have passed since last update.

Laravel(5.5)のLengthAwarePaginatorから表示中の件数from~toを手っ取り早く取り出す

Last updated at Posted at 2019-10-10

要約

ペジネーターをJSON形式にするとfrom, toが取れるので、json_encodeを一旦かませる。

やりたいこと

Laravelのページネーションで、現在表示中のページで
${from} ~ ${to}件表示中 的なのをやりたい。
例を上げると11 ~ 20件表示中 みたいなのです。

対応

Laravel5.5日本語ドキュメントによるとペジネーターをJSON形式にするとfrom, toが取れると記述がある。

一旦JSONにしないといけない。
なのでjson_encode をかませてから json_decode で表示する。

以下具体例

// hoge.blade.php
{{ (json_decode(json_encode($pager)))->from }} ~ {{ (json_decode(json_encode($pager)))->to }}件表示中

参考

Laravel5.5日本語ドキュメント

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0