Пример #1
0
 public function show($code)
 {
     $course = Cache::tags('course')->remember("info-{$code}", Course::MINUTES_PER_MONTH, function () use($code) {
         return Course::with(['semester', 'professors'])->where('code', $code)->orderBy('semester_id', 'desc')->get();
     });
     return $this->setData($course)->responseOk();
 }
Пример #2
0
 /**
  * 將課程資料存到資料庫中.
  *
  * @param array $data
  * @param int $semesterId
  * @return void
  */
 protected function save($data, $semesterId)
 {
     $bar = $this->output->createProgressBar($this->numberOfCourses);
     foreach ($data as $department => $courses) {
         $departmentId = Category::where('category', 'department')->where('remark', $this->departmentTransform($department))->first()->getAttribute('id');
         foreach ($courses as $course) {
             $model = Course::with(['professors'])->where('semester_id', $semesterId)->where('code', $course['code'])->first();
             if (!is_null($model)) {
                 $this->updateCourse($model, $course);
             } else {
                 $this->createCourse($course, ['semesterId' => $semesterId, 'departmentId' => $departmentId, 'department' => $department]);
             }
             $bar->advance();
         }
     }
     $bar->finish();
 }