/** * Processes the form. * * @param string $mode * @param int $id * @return \Illuminate\Http\RedirectResponse */ protected function processForm($mode, $id = null) { $input = array_filter(Input::all()); $rules = ['first_name' => 'required', 'last_name' => 'required', 'email' => 'required|unique:users']; if ($id) { $user = $this->users->createModel()->find($id); $rules['email'] .= ",email,{$user->email},email"; $messages = $this->validateUser($input, $rules); if ($messages->isEmpty()) { $this->users->update($user, $input); } } else { $messages = $this->validateUser($input, $rules); if ($messages->isEmpty()) { $user = $this->users->create($input); $code = Activation::create($user); Activation::complete($user, $code); } } if ($messages->isEmpty()) { return Redirect::to('users'); } return Redirect::back()->withInput()->withErrors($messages); }