検索条件が引き継がれない問題発生
検索機能を実装して、ページネーションで次のページに遷移したとき検索条件が引き継がれない
問題が発生して解決したので記事にしました。
検索をかけて、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() }}