Specs's avatar
Level 4

Laravel scout paginate not working

I create about 300 posts using faker, and use laravel scout to search.

Route::get('search', function () {
    $s = Request::get('s');
    $posts = App\Post::search($s)->paginate(300);
    dd(count($posts));
    //return view('search', compact('posts', 's'));
});

It show that there a about 124 results.

If I change 300 to 10, and use {{ $posts->appends(['s' => $s])->links() }} to show pagination. It show 10 results in the first page. But the pagination only have a disabled « and a disabled ». And if I change page to 2 manually, it can also show 10 results, but no pagination. Why this?

0 likes
19 replies
rodymol123's avatar

I have the same problem, and I can also manually navigate the pages. What driver are you using?

Specs's avatar
Level 4

@rodymol123 I tried the default, elasticsearch and tntsearch. They are all not working.

rodymol123's avatar

@Specs I've tried it with tntsearch; I'm also getting an Offset undefined: 0 error when there are no results. Could you test if you have that?

Specs's avatar
Level 4

@rodymol123 You should re-indexing them, for example php artisan scout:import "App\Post"

timokfine's avatar

I am also having trouble with Scout pagination (using Algolia).

The following returns 20 results:

Thread::search('volup')->get();

If I paginate it, it returns a pagination object as expected:

Thread::search('volup')->paginate(5);

But there are no pagination links being displayed.

If I manually append ?page=2 to the end of my URL, it returns the correct results. It is only the pagination links that are not being displayed.

Weird.

Specs's avatar
Level 4

@timtreks You should use {{ $posts->links() }} in the view to display the pagination.

timokfine's avatar

I have already included the above. I stored my results in a $threads array and passed it to the view with no issues.

KSU_Laracasts's avatar

Same issue here. Tried being strict with:

        {{ $packages->links('vendor.pagination.default') }}

But it returns "Undefined variable: elements"

"If I manually append ?page=2 to the end of my URL, it returns the correct results. It is only the pagination links that are not being displayed."

Same here, manual appendage works...

timokfine's avatar

^ Exact same problem I am having.

Wish I was smart enough to fix this myself and issue a pull request, haha.

RoboRobok's avatar

What is the status of this issue? I still have problems with displaying pagination links in Laravel 5.3 (5.3.10) and newest Scout (1.1.4).

rodymol123's avatar

@RoboRobok The pull-request was merged 18 days ago. It will probably ship with a next update, since 1.1.4 was released 23 days ago. Just use the master branch of scout for now or wait until a release is tagged.

1 like
RoboRobok's avatar

Thanks! I thought it was already merged and that maybe I do something wrong.

JeyBee's avatar

Scout Builder.php already appended 'query' key, so you must use $request->get('query') or change this line return $paginator->appends('query', $this->query); as you desired from scout Builder.php

Please or to participate in this conversation.