public function postStore($id = null) { $validator = Validator::make(Input::all(), User::$rulesEditUser); $data = Input::all(); $user = User::find($id); if (is_null($user)) { App::abort(404); } if ($validator->passes()) { $oldFileName = $user->photo; $user->fill($data); if (Input::hasFile('photo')) { // Get the image input $file = Input::file('photo'); // Save image and crop it $photoName = Client::saveImg($file); // Store photos name $user->photo = $photoName; } else { $user->photo = $oldFileName; } $user->password = Hash::make(Input::get('password')); $user->birthdate = date("Y-m-d", strtotime(Input::get('birthdate'))); $user->save(); return Redirect::to(Input::get('url'))->with('confirmation', '¡Los datos de ' . $user->firstname . ' ' . $user->lastname . ' fueron actualizados!'); } else { // validation has failed, display error messages return Redirect::to(Input::get('url') . '#perfilEdit')->with('message', 'Debes corregir los siguientes campos:')->withErrors($validator)->withInput(); } }
/** * Store a newly created resource in storage. * * @return Response */ public function postStore($id) { $validator = Validator::make(Input::all(), Client::$rulesEditChild); $data = Input::all(); $subclient = Client::find($id); if (is_null($subclient)) { App::abort(404); } if ($validator->passes()) { $oldFileName = $subclient->photo; $subclient->fill($data); if (Input::hasFile('photo')) { // Get the image input $file = Input::file('photo'); // Save image and crop it $photoName = Client::saveImg($file); // Store photos name $subclient->photo = $photoName; } else { $subclient->photo = $oldFileName; } $subclient->save(); return Redirect::to(Input::get('url') . '#sub' . $subclient->id)->with('confirmation', '¡Los datos de ' . $subclient->name . ' fueron actualizados!'); } else { // validation has failed, display error messages return Redirect::to(Input::get('url') . '#subedit' . $subclient->id)->with('message', 'Debes corregir los siguientes campos:')->withErrors($validator)->withInput(); } }