get(); $subjects_ids = $subjects->pluck('id')->toArray(); $classes = Classes::whereIn('subject_id', $subjects_ids)->get(); $classes_grouped = $classes->groupBy($groupBy); return view('user.user_classes', ['classes' => $classes, 'classes_grouped' => $classes_grouped, 'subjects' => $subjects, 'grouped_by' => $groupBy]); } public function add_classes($user_id, Request $request) { $subject_id = $request->input('subject_id'); $date = $request->input('date'); Classes::create([ 'subject_id' => $subject_id, 'date' => $date ]); return redirect(route('user_classes', [$user_id, 'name'])); } public function delete_classes($user_id, $classes_id, $groupBy) { Classes::find($classes_id)->delete(); return redirect(route('user_classes', [$user_id, $groupBy])); } public function edit_classes($user_id, $classes_id, $groupBy) { Classes::find($classes_id); return redirect(route('user_classes', [$user_id, $groupBy])); } }