3
1

More than 3 years have passed since last update.

Laravel ページネーション 検索条件が引き継がれない

Last updated at Posted at 2021-05-21

検索条件が引き継がれない問題発生

検索機能を実装して、ページネーションで次のページに遷移したとき検索条件が引き継がれない
問題が発生して解決したので記事にしました。

検索をかけて、URLを確認すると,下記のように表示されています。


category_id=1&page=1
//検索フォームで検索した結果

そして、2ページ目に遷移すると、

page=2
//ページ遷移した結果

あ、category_id=1が消えていました。
現状、bladeのページネーションのコードを確認すると下記のように設定されています。
 
{{ $projects->links() }}

下記のように変更すると、ページ遷移してもcategory_id=1&page=2
のように引き継がれました。

 
{{ $projects->appends(request()->input())->links() }}

参考記事

3
1
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
3
1