and that error says.... ?
4k is nothing
i need to fetch around 4k records which are going to be printed and shown in blade, but when I use get() or all() I get 500 error
and that error says.... ?
4k is nothing
@Snapey This page isn’t working. is currently unable to handle this request. HTTP ERROR 500.
What does your route, model, controller, view code look like? Check network tab as well. What does error log say?
@jlrdw i am using simple query which is:
$accounts = Acc_account::with("items")->where('cat', 2)->get(); and I foreach it in a blade but the problem is with items that can be 1000k for each account
And what does the 500 error say? 500 is usually a developer mistake.
@Tray2 do you mean sometimes the problem is between the keyboard and the chair? Haha 😁
@jlrdw That is exactly what I am saying.
@Tray2 i agree that sometimes 500 errors cause this problem but in my case If i limit the query with 500 for example it works fine, hence the problem is all about the number of data i am fetching
@Shady Hesham Then you probably run out of memory on the server. I suggest that you either paginate the data, or use ajax to load it increamentally.
@Tray2 thank you for your help, Paginate works fine to surface the data but what about printing?
@Shady Hesham what do you mean by printing?
@shady Try to implement the Laravel Pagination. It is good when you're dealing with a large amount of Data.
@DhPandya I agree with pagination for the displaying. As far as printing @shady hesham
Just suggestion.
Also most bigger companies uses other software as well. One department for the State of Texas would dump the data to local and via an ODBC connection print employee recall rosters via Microsoft Access. The point is only print what is absolutely necessary to print.
@shady https://laravel.com/docs/10.x/eloquent#chunking-results, you can check "lazy collections" and "cursors"
@sylar i have used chunk but i could not print it in blade and here is my code $accounts = Acc_account::where('cat', 2)->chunk(200, function (account) { foreach ($accounts as $account) { // } }); ;
and when I foreach $accounts in blade I get nothing
@Shady Hesham You have a syntax mistake in the posted answer. Please try with the below code.
Acc_account::where('cat', 2)->chunk(200, function (Collection $accounts) {
foreach ($accounts as $account) {
//iterate your accounts here
}
});
@Shady Hesham and please properly format your code, see:
You can send 4000 rows of data to the browser but it's going to potentially take a long time to render.
It all depends on how complicated the view is and you having enough memory to construct the view.
Normally if I'm asked to dump out this much information I would do it as a CSV or excel and then let the user print from that rather from the html.
Please or to participate in this conversation.