/** * Show the form for editing the specified resource. * * @param int $id * * @return Response */ public function edit($id) { $lessonsSubjects = $this->currentUser->lessons()->groupBy('subject_id')->lists('subject_id'); $tutoring = Tutoring::findOrFail($id); $subjects = Subject::whereIn('id', array_flatten($lessonsSubjects))->get(); $modules = Module::whereIn('subject_id', array_flatten($subjects->lists('id')))->get()->map(function ($module) { return (object) ['id' => $module->id, 'name' => "N. {$module->num} - {$module->short_description}", 'subject_id' => $module->subject_id]; }); $classes = $this->currentUser->lessons()->groupBy('class_id')->get()->map(function ($lesson) { return $lesson->schoolClass; }); return view('tutoring.edit', compact('tutoring', 'subjects', 'modules', 'classes')); }
public function __construct(Auth $auth) { parent::__construct($auth); $lessonsSubjects = $this->currentUser->lessons()->groupBy('subject_id')->lists('subject_id'); $this->teacherSubjects = Subject::whereIn('id', array_flatten($lessonsSubjects))->get(); }