May 4, 2023
1
Level 3
Why lazy load return empty collection
I have a package that has multiple departures.
$package->load(['departures' => function ($query) {
$query->select(DB::raw("distinct(DATE_FORMAT(start_date,'%Y-%m')) as start_date"))
->whereDate('start_date', '>', today())
->orderBy('start_date', 'asc');
}]);
but this return an empty unique date collection.
PackageDeparture::where('package_id', $package->id)
->whereDate('start_date', '>', date('Y-m-d'))
->select(DB::raw("distinct(DATE_FORMAT(start_date,'%Y-%m')) as start_date"))
->orderBy('start_date', 'asc')
->get();
while this return all unique dates.
Please or to participate in this conversation.