public function profile() { $user = Auth::User(); $sections = null; $school = null; $teachingSections = null; $allSchools = School::all()->orderBy('id'); $allSections = Section::all(); $i = 0; if ($user->role == 1) { $studentSection = TeachingSection::getTeachingsectionByStudent($user); if ($studentSection === null) { } else { $school = School::getSchoolBySection($studentSection); } return view('users.profile', compact('school', 'user', 'studentSection')); } elseif ($user->role == 2) { $teacherTeachingSections = TeachingSection::getTeachingsectionsByTeacher($user); //$teacherSections有多个teachingSection if ($teacherTeachingSections === null) { } else { $teachedSections = []; foreach ($teacherTeachingSections as $teacherTeachingSection) { $section = Section::find($teacherTeachingSection->sections_id); $teachedSections[i] = $section; $i++; } $school = School::getSchoolBySection($teachedSections[0]); return view('users.profile', compact('school', 'user', 'teachedSections')); } } else { return view('users.newUserProfile', compact('user')); } //如果这个学生没有关联任何班级 $teachingSections = TeachingSection::getTeachingsectionsByUser($user); if ($teachingSections) { $sections = Section::getSectionByteachingSections($teachingSections); $school = School::getSchoolBySection($sections); return view('users.profile', compact('school', 'user', 'sections')); } else { return view('users.profile', compact('school', 'user', 'sections')); } // $sections_id = $teachingSections->id; // print_r($sections_id); // $sections = Section::getSectionByteachingSections($teachingSections); // $school = School::getSchoolBySection($sections); // 容错设计 // echo '--------------------------'; // echo '--------------------------'; // print_r($schoolName); // print_r($teachingSections->id); // print_r($teachingSections->sections_id); // print_r($teachingSections); // return view('users.profile', compact('user')); }
public function newTest() { $user = Auth::User(); $allTeachingSections = TeachingSection::getTeachingsectionsByUser($user); // iterating all teachingSection to get an array of Sections. $allSections = []; $i = 0; foreach ($allTeachingSections as $allTeachingSection) { $allSections[$i] = Section::find($allTeachingSection->sections_id); $i++; } return view('scores.newTest', compact('allSections', 'user')); }