/** * Store a newly created resource in storage. * * @return Response */ public function store() { if (Auth::check()) { $data["inside_url"] = Config::get('app.inside_url'); $data["user"] = Session::get('user'); // Verifico si el usuario es un Webmaster if ($data["user"]->idrol == 1 || $data["user"]->idrol == 2 || $data["user"]->idrol == 3 || $data["user"]->idrol == 4) { // Validate the info, create rules for the inputs $rules = array('id_proyecto' => 'required|unique:reportes_seguimiento|exists:proyectos,id', 'nombre' => 'required', 'departamento' => 'required', 'responsable' => 'required', 'servicio_clinico' => 'required', 'archivo' => 'required|max:15360|mimes:png,jpe,jpeg,jpg,gif,bmp,zip,rar,pdf,doc,docx,xls,xlsx,ppt,pptx'); // Run the validation rules on the inputs from the form $validator = Validator::make(Input::all(), $rules); // If the validator fails, redirect back to the form if ($validator->fails()) { return Redirect::to('reporte_seguimiento/create')->withErrors($validator)->withInput(Input::all()); } else { //dd(Input::all()); $reporte = new ReporteSeguimiento(); $reporte->nombre = Input::get('nombre'); $reporte->id_servicio_clinico = Input::get('servicio_clinico'); $reporte->id_departamento = Input::get('departamento'); $reporte->id_responsable = Input::get('responsable'); $rutaDestino = ''; $nombreArchivo = ''; if (Input::hasFile('archivo')) { $archivo = Input::file('archivo'); $rutaDestino = 'uploads/documentos/investigacion/reporte_seguimiento/'; $nombreArchivo = $archivo->getClientOriginalName(); $nombreArchivoEncriptado = Str::random(27) . '.' . pathinfo($nombreArchivo, PATHINFO_EXTENSION); $uploadSuccess = $archivo->move($rutaDestino, $nombreArchivoEncriptado); $reporte->nombre_archivo = $nombreArchivo; $reporte->nombre_archivo_encriptado = $nombreArchivoEncriptado; $reporte->url = $rutaDestino; } $reporte->id_proyecto = Input::get('id_proyecto'); $reporte->save(); $reporte->codigo = 'RSC-' . date('Y') . '-' . $reporte->id; $reporte->save(); Session::flash('message', 'Se registró correctamente el reporte de seguimiento.'); return Redirect::to('reporte_seguimiento/create'); } } else { return View::make('error/error', $data); } } else { return View::make('error/error', $data); } }