/** * Show the form for editing the specified resource. * * @param $teacherId * @param $lessonId * * @return Response */ public function edit($teacherId, $lessonId) { $teacher = User::findOrFail($teacherId); $lesson = Lesson::findOrFail($lessonId); $subjects = Subject::all(); $classes = SchoolClass::all(); $days = Lesson::getDays(); $adTeachers = Group::findOrFail(3)->users->except($teacherId)->map(function ($user) { return ['id' => $user->id, 'name' => $user->fullName()]; }); $adTeacher = $lesson->teachers->except($teacher->id)->first(); return view('lesson.edit', compact('teacher', 'lesson', 'subjects', 'classes', 'days', 'adTeachers', 'adTeacher')); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $teachers = Group::findOrFail(3)->users()->orderBy('first_name')->get(); $tSubjects = []; foreach ($teachers as $teacher) { $tSubjects[$teacher->id] = []; $teacher->lessons->each(function ($lesson) use($teacher, &$tSubjects) { if (!in_array($lesson->subject->name, $tSubjects[$teacher->id])) { $tSubjects[$teacher->id][] = $lesson->subject->name; } }); } return view('teacher.index', compact('teachers', 'tSubjects')); }