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(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')); } public function delete_classes($classes_id) { Classes::find($classes_id)->delete(); return redirect(route('user_classes')); } public function edit_classes($classes_id) { Classes::find($classes_id); return redirect(route('user_classes')); } }