public function postNewProfile(Request $request) { $user = Auth::user(); /* print_r('--------user in database role value------'); print_r($user->role); print_r('--------user role in request------'); print_r($request->input('role'));*/ // if(($request->has('role'))){ // print_r('has role in request'); // }else{ // print_r('not role in request'); // } //// print_r('--------user name------'); //// print_r($request->input('name')); if ($user->role || $request->has('role')) { if ($request->has('name')) { $user->name = $request->input('name'); } if ($request->has('realname')) { $user->realname = $request->input('realname'); } if ($request->has('role')) { $user->role = $request->input('role'); } if ($request->has('userDescription')) { $user->description = $request->input('userDescription'); } // $user->email = $request ->input('email'); $user->save(); if ($user->role === '1') { // flash()->overlay('你的个人信息修改成功', '成功'); //get students school information $studentTeachingSection = TeachingSection::getTeachingsectionByStudent($user); if ($studentTeachingSection === null) { $user->isdelete = true; //the students should add his or her section. return view('users.studentsProfile', compact('user')); } else { //find the matching section $studentSection = Section::getSectionByteachingSections($studentTeachingSection); //find the matching school. $studentSchool = School::getSchoolBySection($studentSection); $user->isdelete = false; return view('users.studentsProfile', compact('user', 'studentSection', 'studentSchool')); } } elseif ($user->role === '2') { // flash()->overlay('你的个人信息修改成功', '成功'); //get teacher school information $teacherTeachingSections = TeachingSection::getTeachingsectionsByTeacher($user); if ($teacherTeachingSections === null) { // //the teacher should add his or her sections in dashboard, then . // print_r('--------------------------------------------------'); $user->isdelete = true; // print_r($user->isdelete); // print_r('--------------------------------------------------'); // = 1; return view('users.teachersProfile', compact('user')); } else { //find the matching section /* $i= 0; foreach($teacherTeachingSections as $teacherTeachingSection){ $teacherSection = Section::getSectionByteachingSections($teacherTeachingSection); $teachedSections[$i] = $teacherSection; $i++; } $teacherSchool = School::getSchoolBySection($teachedSections[0]);*/ $teacherTeachingSectionsIds = DB::table('teaching_sections')->where('users_id', '=', $user->id)->lists('sections_id'); $teachedSections = DB::table('sections')->whereIn('id', $teacherTeachingSectionsIds)->get(); $teacherSchool = new School(); foreach ($teachedSections as $teachedSection) { $teacherSchool = School::getSchoolBySection($teachedSection); } $user->isdelete = false; /* $teacherSchoolInfo = []; if($user->role == 1){ $user['roleDescription'] = "学生"; }else if($user ->role == 2){ $user['roleDescription'] = "教师"; }*/ return view('users.teachersProfile', compact('user', 'teachedSections', 'teacherSchool')); } } else { return view('users.newUserProfile', compact('user')); // return view('users.teachersProfile', compact('user', 'teachedSections', 'teacherSchool')); } } else { // print_r('--------------------hahahhahahahhahahahah------------------------------'); return view('users.newUserProfile', compact('user')); } }