I have Eloquent with a HasMany relationship. I need to filter only hasmany relationship if the first record is the current month.
Model
public function attendanceclasses(){
return $this->hasMany('App\Studentattendance','assign_id','id')->WhereIn('attendance_status',[2,3,6]);
}
public function firstattendadclass(){
return $this->hasOne('App\Studentattendance','assign_id','id')->WhereIn('attendance_status',[2,3,6])->OrderBy('class_date','ASC');
}
Query
$q->Where('class_date', '>=',date('Y-06-01'));
$q->Where('class_date','<=',date('Y-m-t'));
})->get();