/** * Parse all the courses into Course Objects and save in the database. */ private function parseCourses() { $courses = $this->getCourses(); foreach ($courses as $course) { $number = $course['catalog'][0]; $title = $course['coursetitle'][0]; $subject_code = $course['subject'][0]; try { $subject_title = $course['subjecttitle'][0]; $subject_title = str_replace('Augustana Faculty - ', '', $subject_title); Subject::create(['code' => $subject_code, 'name' => $subject_title]); } catch (Exception $e) { // print("Subject ".$subject_code." already exists.\n"); } $attributes = ['subject_code' => $subject_code, 'number' => $number, 'title' => $title]; try { $course = Course::firstOrNew($attributes); $course->offered_this_semester = true; $course->save(); } catch (Exception $e) { print "Course " . $subject_code . $number . " already exists.\n"; } } }