I am facing an issue which I am looking to overcome. I have a Report that can have many different types of data sets. I have all relations set up appropriately.
Within my show function, when I need to pass this Object to the frontend I do
$dataArray = Report::with(['data_set_a', 'data_set_b', 'data_set_c'])
->where('user_id', Auth::user()->id)->where('id', $id)->first();
Now in most cases this works perfectly, data is passed to the frontend. However, for some reports, data_set_a
has about 20k rows. Locally this is not a problem, but on my live system nothing loads.
I have checked the logs, and mod_security is stating inbound anomaly score exceeded
. I imagine it is not liking the fact that the data set is large and it is blocking it.
As such, I was thinking about adding this data set manually using chunking. So I am attempting something like this
$dataArray = Report::with(['data_set_b', 'data_set_c'])
->where('user_id', Auth::user()->id)->where('id', $id)->first();
DataSetA::where('report_id', $report->id)
->chunk(500, function($data) {
foreach ($data as $row) {
$dataArray['data_set_a'] = array(
'cust_id' => $row->cust_id,
'colOne' => $row->colOne,
'colTwo' => $row->colTwo,
'colThree' => $row->colThree
);
);
}
});
However, I seem to be having issues with the syntax. How can I chunk this data from data_set_a
onto the dataArray?
Thanks
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire