0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Laravel ページネーションのパラメータをシンプルにする

Posted at

appends()の中に$requests->all()を突っ込むと画面ごとにリンクのパラメータを調整する必要がなくなる。
(pageの要素が被るけどページネーションで自動付与されるpageの方で上書きされるので問題ないはず)

ロジック

$page = Model::orderBy('column_name')->paginate(10);

テンプレート

{{ $page->appends($requests->all())->links() }}

ロジック内で初期値を設定している場合

$sort = $requests->input('sort', 'default_value');
if ($requests->has('sort')) {
  $requests->offsetSet('sort', 'default_value');
}

offsetSetでRequestオブジェクトにパラメータを追加できる。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?