public function import(Request $request)
 {
     $file = $request->file('excel');
     //var_dump($filename);
     Excel::load($file, function ($input) {
         $results = $input->all();
         foreach ($results as $result) {
             // Search if a course exist
             $professor = Professor::where('rut', $result->rut)->first();
             // if doesn't exist we save it
             if (!isset($professor)) {
                 $professor = new Professor();
                 $professor->name = $result->nombre_completo;
                 $professor->type = $result->categoria;
                 $professor->rut = $result->rut;
                 $professor->sede_origen = $result->sede_origen;
                 $professor->min_load = $result->carga_docente_minima;
                 $professor->max_load = $result->carga_docente_maxima;
                 $professor->save();
                 //TODO: Pasar esto a el modelo o a una query class
                 $areas = explode(',', $result->areas);
                 foreach ($areas as $key => $area) {
                     $areaIdArray[] = Area::where('name', $area)->first()->id;
                 }
                 $professor->areas()->sync($areaIdArray);
             }
         }
     });
     return redirect()->route('professors.index')->with('message', 'Cursos creados Correctamente.');
 }
 public function edit_profile(Request $request)
 {
     if ($request->image) {
         $professor = Professor::where('user_id', '=', \Auth::user()->id)->first();
         $imageName = "prof_" . $professor->id . '.' . Input::file('image')->getClientOriginalExtension();
         Input::file('image')->move(base_path() . '/public/images/professor/', $imageName);
         $professor->prof_image = $imageName . "";
         $professor->save();
         $professor->update(['firstname' => $request->firstname, 'lastname' => $request->lastname, 'description' => $request->description, 'image' => $imageName]);
         return redirect('/professor')->with('status', 'Profile Updated!');
     } else {
         $professor = Professor::where('user_id', '=', \Auth::user()->id)->first();
         $professor->update(['firstname' => $request->firstname, 'lastname' => $request->lastname, 'description' => $request->description]);
         return redirect('/professor')->with('status', 'Profile Updated!');
     }
 }
 public function decline_prof(Request $request)
 {
     $user = User::find($request->input('prof_id'));
     $institution = Professor::where('user_id', $user['id']);
     $user->delete();
     $institution->delete();
     return redirect('institution/professors-pending');
 }
 public function insert_control(Request $request)
 {
     $professor = Professor::where('id', $request->get('professor'))->first();
     $area = $request->get('area');
     $period = $request->get('period');
     //dd($period);
     $insert_control = Insert_control::where('period', $period)->first();
     if ($insert_control != null) {
         $record = $insert_control;
         $record->available = !$record->available;
         $record->save();
     } else {
         $record = new Insert_control();
         $record->period = $period;
         $record->available = 1;
         $record->save();
     }
     return redirect("schedules/{$period}/{$area}/{$professor->id}");
 }