Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

clat23's avatar

How to specify page number to retrieve on a Laravel Scout search

I've read the documentation on Laravel Scout Pagination:

https://laravel.com/docs/5.6/scout#pagination

However the documentation does not specify how to retrieve other pages. How would I go about doing this?

0 likes
5 replies
jlrdw's avatar

From docs

$orders = App\Order::search('Star Trek')->paginate(15);

Like a google search, first search page will be page one. I must be really mis-understanding the question.

Also from docs:

Once you have retrieved the results, you may display the results and render the page links using Blade just as if you had paginated a traditional Eloquent query:

<div class="container">
    @foreach ($orders as $order)
        {{ $order->price }}
    @endforeach
</div>

{{ $orders->links() }}   ///HERE  HERE
clat23's avatar

Umm... I did start the question saying I read the docs didn’t I? I even provided the link to the part of the documentation that I read.

I’m sorry, my question was probably too vague. I’ll blame it on research fatigue. I’ve clicked on every first page google search result and no answer.

My problem is not with the pagination links. I checked the generated URL and it ends like this ...?query=[my query term here]&page=2 but when I click on it, it returns not only the first page, but it loses my query and returns all my records.

I’m trying to catch the request after clicking the page links and doing something like this:

$model = Model::search($request->query[‘query’], [‘page’ => ‘2’])->get()

But I don’t think the search method accepts a second parameter for options. So how do I pass query options to get the right page and query?

newbie360's avatar

you means want to the ?query=keyword on every page link ?

$keyword = $request->query('query');
$orders = App\Order::search($keyword)->paginate(15);
$orders->appends(['query' => $keyword]);

so in the view just use

{{ $orders->links() }}
jlrdw's avatar

@clat23 appending to query string is no different than regular pagination.

And your original question is a little vague.

the documentation does not specify how to retrieve other pages. How would I go about doing this?

Was your question.

And you can append the query string in the controller or in The View.

If you are unfamiliar with a appending a query string work the examples under normal laravel pagination first.

1 like
clat23's avatar
clat23
OP
Best Answer
Level 3

@clat23 appending to query string is no different than regular pagination.

Thank you that pointed me to the correct answer which is that I do not need to specify page numbers and the original query as Laravel handles that. I was over complicating things. I was reading the Algolia docs and saw that page numbers needed to be passed in the options of the search request. But again, Laravel handles that.

Please or to participate in this conversation.