doujuan9698 2013-08-27 02:31
浏览 30
已采纳

重置电子邮件/密码

I have a page setup to reset the user's email address password and the users zip_code for an application. I have it working correctly however, if for example I want to just change the zip code my validation will not allow it due to it reading the email as already existing in the database and returns an error. What is the best way around this? I could create a controller for each field and do it individually but I feel there is some if statement I could use maybe?

Controller:

enter        
public function getEditUser() {
    $userdata = array(
        'email'            => Input::get('email'),
        'password'         => Input::get('password'),
        'confirm_password' => Input::get('confirm_password'),
        'user_zip_code'    => Input::get('user_zip_code')
    );

    $rules = array(
        'email'            => 'required|email|unique:users,email',
        'password'         => 'required|min:5',
        'confirm_password' => 'required|same:password',
        'user_zip_code'    => 'required'
    );

    $validation = Validator::make($userdata, $rules);
    if ($validation->fails()) {
        return Redirect::to('dashboard/edit/account')->withErrors($validation)       
            ->withInput();
    }

    $userdata['password']         = Hash::make($userdata['password']);
    $userdata['confirm_password'] = Hash::make($userdata['confirm_password']);

    User::find(Auth::user()->id)->update($userdata);

    return Redirect::to('dashboard');
} 

Unique needs to be in place obviously so it doesn't get matched with another account

Also my email is set through Auth..Auth::user()->email if that helps

  • 写回答

1条回答 默认 最新

  • duanlei2150 2013-08-27 03:15
    关注

    You can set the validation unique rule to ignore the current id

    $rules = array(
                    'email' => 'required|email|unique:users,email,'.Auth::user()->id,
                    'password' => 'required|min:5',
                    'confirm_password' => 'required|same:password',
                    'user_zip_code' => 'required'
                );
    

    See here for more info from the docs

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了