use*_*101 3 passwords field laravel
我想检查某个字段是否为空。如果为空,则用户可以更新配置文件而无需更改当前密码。如果不为空,则存储密码的新值。我的控制器是:
public function storeUpdatedUser(Request $request)
{
$this->validate($request, ['email' => 'required', 'name' => 'required', 'surname' => 'required', ]);
$user = User::findOrFail(Auth::user()->id);
$user->update($request->all());
$new_password = false;
if($new_password != ""){
$new_password = bcrypt($request->new_password);
$user->password = $new_password;
}
$user->save();
Session::flash('flash_message', 'User updated!');
return redirect('/');
}
Run Code Online (Sandbox Code Playgroud)
尝试这个:
public function storeUpdatedUser(Request $request)
{
$this->validate($request, ['email' => 'required', 'name' => 'required', 'surname' => 'required', ]);
$user = User::findOrFail(Auth::user()->id);
$user->update($request->all());
if(!empty($request->input('new_password'))) {
$new_password = bcrypt($request->input('new_password'));
$user->password = $new_password;
$user->save();
}
Session::flash('flash_message', 'User updated!');
return redirect('/');
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7408 次 |
| 最近记录: |