本文整理汇总了PHP中app\Course::firstOrNew方法的典型用法代码示例。如果您正苦于以下问题:PHP Course::firstOrNew方法的具体用法?PHP Course::firstOrNew怎么用?PHP Course::firstOrNew使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Course
的用法示例。
在下文中一共展示了Course::firstOrNew方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseCourses
/**
* 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";
}
}
}