princeallan5's avatar

Laravel-Vue data pagination and filtering through all records

Hi,

I created a laravel-vue app. I paginated results displaying 50 records at a time. That was all easy.

Now, I have over a thousand records, and I need to be able to filter through all records over 1000. I can only filter the results I already returned on single page using Data binding.

Can anyone help me with a simple solution on how to update result while filtering (filtering through the all 1000 records) with included pagination?

I hope I'm clear enough!

Regards

0 likes
1 reply
flightsimmer668's avatar

I hope I'm understanding the problem clearly -- you should be filtering your query before you paginate the results. By paginate, I mean that by calling the ->paginate(50); method. For example:

Record::where('artist_id', '=', 33)->where('title', 'like', '%' . 'Awesome' . '%')->paginate(50);

The ->where methods in this example are filtering the query results before they are paginated and sent back to your Vue app.

There are also more pagination examples with some filtering in the Laravel Documentation https://laravel.com/docs/7.x/pagination#paginating-eloquent-results

1 like

Please or to participate in this conversation.