Don't make things harder than they have to be read this: http://laravel.io/forum/04-04-2015-looping-through-collection I've run accounts receivable an accounts payable reports this way.
Complex Query for a Report
I am trying to get 3 eloquent queries that need for a report to line up on all the ids so I can run foreach loops to get the data i need. I need to spit out each agencies license group and then their corresponding order details.
Here as my 3 queries:
$agencies = Agency::with('[orders.person.state', 'orders.organization.state', 'orders.orderdetails'])->whereHas('orders.orderdetails', function($q) use ($startDate, $endDate) { $q->whereBetween('created_at', [Cabon::parse($startDate), Carbon::parse($endDate); })->get();
$orderDetails= OrderDetail::with('[licenses.licensegroup',])->whereBetween('created_at', [Cabon::parse($startDate), Carbon::parse($endDate)]); })->get();
$licenseGroups=LicenseGroup::with([ 'licenses.orderdetails', 'licenses.orderdetails.order.person.state', 'licenses.orderdetails.order.agency', 'licenses.orderdetails.order.organization.state'])->whereHas( 'licenses.orderdetails', function ($q) use ($startDate, $endDate) { $q->whereBetween('created_at', [Cabon::parse($startDate), Carbon::parse($endDate)]); })->get();
Right now i cannot get the dates to work? My guess is because it is on the collection as a whole. Any Ideas on the dates, a well as how I can link these all up together to create my report?
Please or to participate in this conversation.