public function test() { $groups = DepartmentSubject::Where('department_id', 1)->groupBy('group')->lists('group'); foreach ($groups as $group) { ${$group} = $department_subjects = DepartmentSubject::Where('department_id', 1)->where('group', $group)->get(); } $data = []; foreach ($groups as $group) { $data[$group] = ${$group}; } $data['groups'] = $groups; return view('test', $data); }
public function single_department($department_id) { $groups = DepartmentSubject::Where('department_id', $department_id)->groupBy('group')->lists('group'); $department_name = DepartmentSubject::find($department_id)->department->department_name; foreach ($groups as $group) { ${$group} = $department_subjects = DepartmentSubject::Where('department_id', $department_id)->where('group', $group)->get(); } $data = []; foreach ($groups as $group) { $data[$group] = ${$group}; } $data['groups'] = $groups; $data['department_name'] = $department_name; return view('admin.department_subject.department_subject_single', $data); }