1
1

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 1 year has passed since last update.

Laravel Scout の paginate が query を使用すると機能しない

Last updated at Posted at 2020-09-01

バージョン

Laravel5.4

問題

query を使用してオブジェクトを取得しようとするとページネーションが機能しない問題が発生します。

Post::search($request->input('keyword'))->query(function ($query) {
                $query->filter();
            })
                ->paginate(50);

解決方法

初めに全文検索のみ行い、一致したレコードのIDリストを返します。

$ids = Post::search($request->input('keyword'))->keys()->toArray();
Post::whereIn('id', $ids)->filter()->paginate(50);
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?