/** * Display the instructor profile. * * @return Response */ public function getProfile($id = Null) { if (isset($id)) { //The instructor with the given user_id $instructor = User::with('instructor')->has('instructor')->where('active', 1)->find($id); if (count($instructor) == 1) { //Instructor_id of the instructor $instructor_id = $instructor->instructor->instructor_id; //All reviews of the instructor $reviews = Instructor::find($instructor_id)->reviews()->orderBy('created_at', 'desc')->paginate(2); $reviews->setPath('/drive/instructor/profile/83/url'); //Counting the number of reviews wrote by the current learner for the instructor // $no_of_review = Review::where('learner_id', Auth::user()->learner->learner_id)->where('Instructor_id', $instructor_id)->count(); //Counting total number of reviews of the instructor $total_reviews = Instructor::find($instructor_id)->reviews()->count(); //Calculating the average rating $avg_rating = Instructor::find($instructor_id)->reviews()->avg('rating'); // $images = Image::where('instructor_id', $instructor_id)->get(); //Returning the view with $instructors return view('instructor_profile', ['instructor' => $instructor, 'reviews' => $reviews, 'total_reviews' => $total_reviews, 'avg_rating' => $avg_rating, 'images' => $images]); } else { //If no result, redirect the user to the instructor_list //Flashed data contains message and alert-danger class return redirect()->action('InstructorController@getIndex')->with('message', 'No instructor profile found!')->with('alert-class', 'alert-danger'); } //End of if statement } else { //If no id provided, redirect the user to the instructor_list return redirect()->action('InstructorController@getIndex'); } //End of if statement }
public function update(Request $request, $id) { $instructor = Instructor::find($id); $instructor->fill($request->all()); $instructor->save(); Flash::warning('Instructor ' . $instructor->name . ' se ha modificado correctamente'); return redirect()->route('register.instructors.index'); }