Reputation: 7138
I need to get data that has been created from 10 minutes ago till now but it returns wrong results
$defs = OrderDefaultProgress::where('name', 'Laundry Mencari supir')->pluck('id')->toArray();
$progresses = OrderProgress::where('created_at', '<=', Carbon::now()->subMinutes(10))->whereIn('progress_id', $defs)->get();
$progresses
return data with time stamp of 2021-02-07T09:15:44.000000Z
while this data is belong to 8 hours ago.
[
{
"id": "7ce3bd58-3f19-4de9-8b92-e196d6e7b97f",
"order_id": "175fe9ed-6932-4d5e-ba8f-ec36acf7d872",
"progress_id": "b816f3bf-9c58-4e77-8d67-b834cac4ae77",
"created_at": "2021-02-07T09:15:44.000000Z",
"updated_at": "2021-02-07T09:15:44.000000Z"
}
]
Strange thing is that in my database I don't even have such timestamp!
Upvotes: 1
Views: 675
Reputation: 1004
Do not use from 'where' in here, use from whereBetween
inested of where
like:
OrderProgress::whereBetween('created_at', [Carbon::now()->subMinutes(10), Carbon::now()])->whereIn('progress_id', $defs)->get();
I hope this work for you.
Upvotes: 5
Reputation: 8618
Need use code like this
$progresses = OrderProgress::where('created_at', '>=', Carbon::now()->subMinutes(10))->whereIn('progress_id', $defs)->get();
Upvotes: 3
Reputation: 4271
You should use whereDate
method
OrderProgress::whereDate('created_at', '>=', Carbon::now()->subMinutes(10))
->whereIn('progress_id', $defs)->get();
Upvotes: 2