Merhabalar aşağıda yazdığım kod tarih filtrelemesinin dışında ki tarihleri de getiriyor çözümünü bulamadım rica etsem yardımcı olur musunuz ?
$filter_start_date = "2023-08-02" . ' 00:00:00';
$filter_end_date = "2023-12-16" . ' 23:59:59';
$result = Order::with('packing', 'company', 'currency_unit')
->whereHas('packing', function ($query) use ($filter_start_date, $filter_end_date) {
$query->where('status_id', 27);
})
->when([$filter_start_date, $filter_end_date], function ($query) use ($filter_start_date, $filter_end_date) {
if ($filter_start_date && $filter_end_date) {
$query->whereHas('packing', function ($q) use ($filter_start_date, $filter_end_date) {
$q->whereBetween('created_at', [$filter_start_date, $filter_end_date]);
});
}
});
$data = $result->get();
$tmpData = [];
foreach ($data as $row) {
foreach ($row->packing as $packing) {
array_push($tmpData, ['data' => $packing->created_at]);
}
}
$tmpData = collect($tmpData)->sortByDesc('data')->toArray();
json_encode($tmpData);