public function index()
 {
     $years = SchoolYear::all();
     $current_year = $years->pop();
     $current_handbook = $current_year->course_handbook;
     $handbooks = CourseHandbook::all();
     return view('configuracion.anos-lectivos')->with(compact(['years', 'current_year', 'current_handbook', 'handbooks']));
 }
 public function index($handbook_id, $grade_id)
 {
     $handbook = CourseHandbook::find($handbook_id);
     // Get all courses and grades to fill the selects
     $courses = Course::all();
     $grades = Grade::all();
     // Select the grade and its courses associated in the current handbook
     $current_grade = Grade::find($grade_id);
     $current_courses = CourseGrade::where('course_handbook_id', $handbook_id)->where('grade_id', $grade_id)->get(['course_id']);
     $current_courses = $this->convertToCourseCollection($current_courses);
     return view('configuracion.asignar-cursos')->with(compact(['handbook', 'courses', 'grades', 'current_courses', 'current_grade']));
 }
 public function destroy($id)
 {
     $course_handbook = CourseHandbook::find($id);
     $relations = $course_handbook->course_grade_relations;
     if ($relations->count() > 0) {
         return back()->with('error', 'No es posible eliminar una malla curricular con cursos asignados.');
     }
     $school_years = $course_handbook->school_years;
     if ($school_years->count() > 0) {
         return back()->with('error', 'No es posible eliminar una malla curricular si está asignada a un año lectivo.');
     }
     $course_handbook->delete();
     return back();
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     CourseHandbook::create(['name' => 'Malla curricular 2016', 'description' => 'Malla curricular actual de la institución educativa.']);
 }