Merhabalar aşağıdaki iki kod arasında nasıl bir fark var hangisi daha performanslı çalışır veya hangisi bu filtreleme işlemi için doğru bir yapı ?
Order::with(['example_table' => function ($query) use ($supplier_company_id, $filter_start_date, $filter_end_date) {
if ($supplier_company_id) {
return $query->where('supplier_company_id', $supplier_company_id)->whereBetween('created_at', [$filter_start_date, $filter_end_date]);
}
return $query->whereBetween('created_at', [$filter_start_date, $filter_end_date]);
}])->whereHas('example_table'),
Order::with('example_table')
->whereHas('example_table',function ($query) use ($supplier_company_id, $filter_start_date, $filter_end_date) {
if ($supplier_company_id) {
return $query->where('supplier_company_id', $supplier_company_id)->whereBetween('created_at', [$filter_start_date, $filter_end_date]);
}
return $query->whereBetween('created_at', [$filter_start_date, $filter_end_date]);
})