FabLPA's avatar

Search results with pagination but also containing information on all data without regard to pagination

Hi People,

For a customer, I'm developing an API for an online book catalog and I'm drying out on a feature, or more specifically on some part of this feature.

An example of what I try to obtain: https://bibliotheque.braille.be/fr/catalogue?filters%5Bsearch%5D=King

On the left is a column of sub-filters that is based on all the results of the search.

And on the right, the list of books with pagination.

Do you have any idea of how I can build my query to have pagination AND "filters" based on the entire search result?

It's probably stupid as cabbage, but probably too much head on the handlebars to find the solution ...

What I use for the moment:

  • a Controller which receives in POST the fields of the search form
  • a Service that performs the search in the db
  • a Resource that is returned to the front-end by the Controller

If I do that in my controller:

$response = $ bookServices-> search ($ request);
$bookGlobal = BookResource :: collection ($ response-> get ());
$bookPaginate = BookResource :: collection ($ response-> paginate ($ request-> perPage));

return response () -> json (['books' => $ bookPaginate, 'filters' => $ bookGlobal], 201);

It returns to me my paginated books (books) and books without pagination (filters) that will allow me in front of "build" the left column, but it's a little devil ... I lose the pagination info for " books ", and the loading time is not great.

By doing that :

$ response = $ bookServices-> search ($ request, false);

return BookResource :: collection ($ response-> paginate ($ request-> perPage));

The answer contains the pagination info, but I have nothing complete to build the left column.

An idea ?

Laravel version: 5.8

And sorry for my poor English...

0 likes
0 replies

Please or to participate in this conversation.