Ejemplo n.º 1
0
 public function update($id)
 {
     $data = array("first_name" => Input::get("first_name"), "last_name" => Input::get("last_name"), "email" => Input::get("email"), "phone" => Input::get("phone"), "picture" => Input::file("picture"), "specialty_id" => Input::get("specialty_id"), "dating_duration" => Input::get("dating_duration"));
     $rules = array("first_name" => 'required|min:1|max:255', "last_name" => 'required|min:1|max:100', "email" => 'required|min:1', "phone" => 'required|min:1|max:100', "specialty_id" => 'required|min:3|max:255', "dating_duration" => 'required|min:1|max:3', "picture" => 'mimes:jpeg,gif,png');
     $messages = array('required' => 'El campo :attribute es obligatorio.', 'min' => 'El campo :attribute no puede tener menos de :min carácteres.', 'email' => 'El campo :attribute debe ser un email válido.', 'max' => 'El campo :attribute no puede tener más de :max carácteres.', 'numeric' => 'El campo :attribute debe contener solo numeros', 'mimes' => 'El formato de la imagen logo debe ser jpg, git, png');
     $validation = Validator::make(Input::all(), $rules, $messages);
     //si la validación falla redirigimos al formulario de registro con los errores
     //y con los campos que nos habia llenado el usuario
     if ($validation->fails()) {
         return Redirect::to('/doctor/profile')->withErrors($validation)->withInput();
     } else {
         $doctor = Doctor::find($id);
         $agenda = Agenda::where('doctor_id', $doctor->id)->first();
         $agenda->dating_duration = Input::get("dating_duration");
         $agenda->save();
         $espes = explode(',', Input::get("specialty_id"));
         $espeuok = '';
         foreach ($espes as $espe) {
             $very = Specialty::where('name_es', $espe)->first();
             if ($very) {
                 $espeuok = $espeuok . ',' . $very->id;
             }
         }
         $doctor->specialty_id = $espeuok;
         $doctor->save();
         $user = User::find($doctor->user_id);
         $user->first_name = $data['first_name'];
         $user->last_name = $data['last_name'];
         $user->save();
         $profile = Profile::where('user_id', $doctor->user_id)->first();
         if (Input::file('picture') != NULL) {
             //agrega imagen de logo
             $file_logo = Input::file('picture');
             $ext = Input::file('picture')->getClientOriginalExtension();
             $nameIMG = date('YmdHis');
             $logo = $nameIMG . '.' . $ext;
             $logo = 'assets/doctor/images/profile_pic/profile_' . $logo;
             $profile->picture = $logo;
         }
         $profile->phone = Input::get("phone");
         $profile->save();
         if ($profile) {
             if (Input::file('picture') != NULL) {
                 $file_logo->move("assets/doctor/images/profile_pic/", $logo);
             }
             return Redirect::to('/doctor/profile')->withFlash_message("Guardado Exitosamente");
         } else {
             return Redirect::to('/doctor/profile')->withErrors("Error")->withInput();
         }
     }
 }
 public function edit($id)
 {
     if (Payment::VeryPayment() == false) {
         return View::make('clinic.payment.renews-payment');
     }
     $user = Sentry::getUser();
     $clinic = Clinic::where('user_id', $user->id)->first();
     $doctor = Doctor::where('clinic_id', $clinic->id)->where('id', $id)->first();
     $agenda = Agenda::where('doctor_id', $doctor->id)->first();
     $esps = explode(',', $doctor->specialty_id);
     $espok = '';
     $array = array();
     foreach ($esps as $esp) {
         $very = Specialty::where('id', $esp)->first();
         if ($very) {
             $array[] = array('value' => $very->id, 'text' => $very->name_es);
         }
     }
     $profile = Profile::where('user_id', $doctor->user_id)->first();
     return View::make('clinic.doctors.edit', ['agenda' => $agenda, 'doctor' => $doctor, 'profile' => $profile, 'specialty' => $array]);
 }