如何散列密码 laravel 5.2 模型创建
how to hash a password laravel 5.2 model create
我正在通过模型创建管理员用户并成功保存记录,但密码未按如下方式进行哈希处理:
$request->password = bcrypt($request->input('password'));
Admin::create($request->except('_token'));
您不能那样修改 $request 属性。
试一试:
$input = $request->except('_token');
$input['password'] = bcrypt($input['password']);
Admin::create($input);
或者,在您的管理模型中处理它
public function setPasswordAttribute($value)
{
$this->attributes['password'] = bcrypt($value);
}
那你可以
Admin::create($request->except('_token'));
看看 Laravel 的 Hashing documentation。它表明您应该像这样散列任何字符串:
Hash::make($request->newPassword)
但是看看你的代码,我会说这个问题实际上是你试图修改请求 $request->password
,这不会像你期望的那样工作。查看您的 Admin 模型 class 并查看代码预期的内容,如果您传递正确的参数,这可能已经内置。
我正在通过模型创建管理员用户并成功保存记录,但密码未按如下方式进行哈希处理:
$request->password = bcrypt($request->input('password'));
Admin::create($request->except('_token'));
您不能那样修改 $request 属性。
试一试:
$input = $request->except('_token');
$input['password'] = bcrypt($input['password']);
Admin::create($input);
或者,在您的管理模型中处理它
public function setPasswordAttribute($value)
{
$this->attributes['password'] = bcrypt($value);
}
那你可以
Admin::create($request->except('_token'));
看看 Laravel 的 Hashing documentation。它表明您应该像这样散列任何字符串:
Hash::make($request->newPassword)
但是看看你的代码,我会说这个问题实际上是你试图修改请求 $request->password
,这不会像你期望的那样工作。查看您的 Admin 模型 class 并查看代码预期的内容,如果您传递正确的参数,这可能已经内置。