public function postUpdate() { $title = 'Editar usuario'; $branches = Branche::all(); $input = array_except(Input::all(), array('_method', 'password2')); $id = $input['id']; $rules = array('name' => 'required', 'email' => 'required|email', 'password' => 'required'); $v = Validator::make($input, $rules, User::$messages); if ($v->passes()) { $password = $input['password']; $password = Hash::make($password); $user = $this->user->find($id); $user->name = $input['name']; $user->email = $input['email']; $user->password = $password; try { $user->save(); } catch (Exception $e) { // $message = $e->getMessage(); $message = 'No se han guardado cambios porque hay otro usuario con ese nombre o email.'; Session::flash('message', $message); return View::make('users.edit')->with(compact('title', 'user', 'branches')); } try { $rol = $user->roles()->first(); $r['name'] = $input['rol']; $r['branch_id'] = $input['branch']; $r['user_id'] = $user->id; $rol->update($r); return Redirect::to('users/list'); } catch (Exception $e) { $message = 'No se ha podido asignar el rol al usuario <strong>' . $user->name . '</strong>.'; Session::flash('message', $message); return View::make('users.register')->with(compact('title', 'user', 'branches')); } return Redirect::to('users/list'); } return Redirect::to('users/edit/' . $id)->withInput()->withErrors($v)->with('message', 'Hay errores de validación.'); }
public function getSelect() { $title = "Sucursales"; $branches = Branche::all(); return View::make('branches.select')->with(compact('branches', 'title')); }