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

EmilMoe's avatar

Select Eloquent collection around model

I am trying to make a combobox that always contains the selected item. With combobox I mean a searchable select where not all results are listed.

So for instance I have selected user id "150" with name "John Doe", I want to get a result with ie. 5 users before John Doe and 5 after.

There must be someone who solved this before? Or would you tackle the problem completely different?

I also need arrows back- and forward, so at minimum I would need to know the previous and next in the database (on the way it is sorted).

0 likes
3 replies
Tray2's avatar

So you mean that you need something like*

  • Eric
  • Dave
  • Steve
  • Ethan
  • Taylor
  • John Doe (Selected)
  • Sabrina
  • Miranda
  • Mike
  • Robert
  • Carl
Snapey's avatar

So for instance I have selected user id "150" with name "John Doe", I want to get a result with ie. 5 users before John Doe and 5 after.

So, you press down arrow, what happens? A round trip to the server to select the new range?

It does not seem very efficient. You would be better getting the whole collection and paging it locally in the browser.

jlrdw's avatar

I prefer a lookup table, with full search and pagination.

Just example here: https://laracasts.com/discuss/channels/laravel/can-i-redirect-a-get-request-to-a-post-request-for-inertia-partial-reloads?page=1&replyId=905775

And if I need to search like last name starts with (Smi) I just enter that and the search results start there.

And I do mean server side pagination.

We had one poster who literally got over a million results and wanted to paginate that client side. Don't do that.

Let the database do it's job.

Please or to participate in this conversation.