Get records where created_at the date is less today
Hello!
How I can get records where created_at the date is less today but not older less 5 days?
Control::with(['shop.documents' => function ($query) {
$query->whereIn('doc_type', [1,4]);
}])->whereDate('created_at', '<=', today()->subDays(5))
->whereDate('created_at', '<=', today())
->get()
I trying some like this but this is not working.
Thanks
Control::with(['shop.documents' => function ($query) {
$query->whereIn('doc_type', [1,4]);
}])->whereBetween('created_at', [today()->subDays(5), today()])
->get()
Your original effort has the incorrect comparison ->whereDate('created_at', '<=', today()->subDays(5)); it should be
->whereDate('created_at', '>=', today()->subDays(5))
and try not to use magic numbers
$query->whereIn('doc_type', [1,4]);
use constants or enums
How does someone reading your code know what 1 or 4 means?
Please or to participate in this conversation.