I got a query with many joins, wheres, ect. And what I need to do is insert some maths into each result set as it will be feeding either a csv export or be displayed on page. Can later on even be sent back as API, so what I really want to do is prepare the data once, and then use it where ever.
$result = DB::table('a')
->join('b')
->where('c')
->orderBy('d')
->select('e');
if ($paginate) {
$query->paginate();
} else {
$query->get();
}
So the question is, can I somehow iterate through my results and do some maths as I get them? Like maybe a callback on each result?
For example get difference between some values retrieved in each row, or add in additional row signifying pass/fail. Basically I was wondering if there was a better way of doing things then later on doing a foreach() on the results to go through them, do the maths and add in additional columns, thereby destroying the pagination support and having to convert the result into an ugly array?