Skip to content

Instantly share code, notes, and snippets.

@tisuchi
Last active November 26, 2022 17:37
Show Gist options
  • Save tisuchi/f434242e68cef9de5621ebb7e3f0b4c4 to your computer and use it in GitHub Desktop.
Save tisuchi/f434242e68cef9de5621ebb7e3f0b4c4 to your computer and use it in GitHub Desktop.
<?php
public function upgradeMgmlCycle($studentInfo)
{
if ($studentInfo->cycle_end >= now()->today()) {
return $studentInfo;
}
if (!$studentInfo->cycle >= $studentInfo->mgml_syllab_cycle) {
$studentInfo->cycle = $studentInfo->cycle + 1;
$studentInfo->cycle_start = now()->firstOfMonth();
$studentInfo->cycle_end = $this->addMonthsAndGettLastDayOfMonth($studentInfo->mgml_syllab_unit_per_cycle - 1);
return $studentInfo;
}
}
// mgml_cycle_scores
// - student: belongsTo
// students
// - mgml_cycle_scores: hasMany
// - center: belongsTo
// center
// students: hasMany
// Other approach
// 1
Student::with(['center', 'mgml_cycle_scores'])
->Active()
->whereHas('center', function ($query) {
$query->where('center_type_id', $this->mgml_center_type_id);
})
->whereHas('mgml_cycle_scores', function ($query) {
$query->groupBy('subject_id', 'student_id');
})
->get();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment