0
It wasn’t very clear to me how the documentation works and I couldn’t find any content to fully explain how to use chunkById() and the difference practices for Chunk();
How do I return the result of chunkById() to the view? How do I paginate these records in the view? The way below doesn’t work...
DB::table('fornecedores')->orderBy('razao')->chunkById(100, function($fornecedores){
foreach ($fornecedores as $fornecedor) {
DB::table('fornecedores')
->where('id', $fornecedor->id);
}
I know the paginate, but for example, I have 100,000 suppliers in my bank, I want to limit to improve performance. If I limit to 1000 using Chunk, I can’t page that 1000? or Chunk doesn’t serve to return data for view listing?
– user143874
@user143874 depends, you want to page only the 1000 record or the 100 thousand?
– fajuchem
@user143874 Would you use simplePaginate to be more efficient, but would only have the next and Previous button, another thing that can be done to greatly improve the performance is to put in the query the columns you need, for example if the vendors table has 50 Columns and you only use the id and name in the listing, the query you used will return the 50 and not only the 2 Columns used in the view.
– fajuchem