Alright so I have been looking for hours for an answer but can't seem to find one. I have an array of "orders" all for different dates. I get all of the orders for this week, this should not be an issue, then I want to a tab for each day of the week.
What I have tried so far is this:
$dinnerOrders->where('date','>',$date)->where('date','<', $date->endOfDay())->sortBy('created_at');
Where $date is :
$dt = Carbon\Carbon::create()->startOfWeek();
Carbon\Carbon::setTestNow($dt);
$date = new Carbon\Carbon('this ' . $day);
And $dinnerOrders are get by:
$dinnerOrders = collect([]);
foreach($restaurant->dinners as $dinner) {
foreach($dinner->orders as $order) {
$dinnerOrders[$order->id] = $order;
}
}
The dates seem correct and it words in sql. Is this not working because $dinnerOrders is a collection?
What I'm getting is nothing, i.e an empty set, despite it working in mysql terminal.
So what I'm asking is perhaps, can you do a date comparison on a collection? If so, how?
get()
to retrieve your results, usetoSql()
and that will return a string with the SQL query that is being built and run by the Query Builder. Does that match what you are running manually? – Coenosarc