cyberfly
6/28/2018 - 3:45 AM

Laravel relationship filter on controller

$year = 2018; 
$authors = Author::with(['books' => function($query) use ($year) {
  $query->whereYear('created_at', $year);
}])->get();