2017-04-20 11 views
0

Eloquent/Query Builder와 관계를 사용하는 방법을 이해하는 데 어려움을 겪고 있습니다.Laravel EQ 별 관계 별 그룹

나는 다음과 같습니다

$plantLots = PlantLot::with('controlNumber') 
    ->whereHas('controlNumber', function ($q) use ($fromDate, $toDate) { 
     $q->where('created_at', '>=', $fromDate); 
     if($toDate != '') { 
      $q->where('created_at', '=<', $toDate); 
     } 
     $q->groupBy('creator_id'); 
    })->get(); 

내가 creator_id에 의해 그룹화 할,하지만 난 여전히 하나의 데이터 집합을 얻을.

내가 뭘 잘못하고 있니?

$plantLots = PlantLot::with(['controlNumber' => function($q){ 
     $q->groupBy('creator_id'); 
    }]) 
    ->whereHas('controlNumber', function ($q) use ($fromDate, $toDate) { 
    $q->where('created_at', '>=', $fromDate) 
     ->when($toDate != '',function($q){ 
     $q->where('created_at', '=<', $toDate); 
     }); 
    })->get(); 

답변

0

변화 그것이 도움이되기를 바랍니다.