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

Ligonsker's avatar

Real time search + pagination

Hello,

I currently use Laravel's pagination and whenever I need a search feature I simply add a search box that, when submitted, saves the value in a session key in the backend and then it refreshes the page with the filtered query.

Now I want to change it to be real time search so that the page won't refresh.

In this case, should I completely stop using the Laravel pagination and do everything with JS? For example for the links and the number of links use a query that counts the results, and a query that fetches the data according to the page.

Or any other idea?

Thanks

0 likes
7 replies
Ligonsker's avatar

But I can't use Livewire right now :/ if I could I would give it a try

1 like
Alexzz's avatar

you could still use laravel and return the data for that page as json, so basically make an API for that page and use the generated pagination

2 likes
Ligonsker's avatar

@Adamzz So if for example I already have some page that uses pagination:

public function my_page(Request $request)
{
    // some more stuff to gather

    return view('user.index', [
    'users' => DB::table('users')->paginate(15)
    'some_other_data' => $some_other_data
    ]);
}

I need to change to JSON (Or instead of change, add another endpoint because I still need the original view):

public function my_page_api(Request $request)
 {
    // some more stuff to gather

    return response()->json([
    'users' => DB::table('users')->where('some_column', '=', $request->input('search'))->paginate(15)
    'some_other_data' => $some_other_data
    ]);
}
jlrdw's avatar
jlrdw
Best Answer
Level 75

Just use a server fetched partial.

2 likes

Please or to participate in this conversation.