What happens if you try:
Route::get('/', function() {
$user = User::find(39);
echo ' Before Save: ' . $user->getAuthPassword();
$user->email = '[email protected]';
$user->password = Hash::make('aaaaaaaa');
$user->save();
echo ' After Save: ' . $user->getAuthPassword();
dd($user);
});
The User model encrypts your password when saving it to the database, your password will not be in plain text.
thanks for help, i know we have to encrypts passwd before save so i have put that code public function setPasswordAttribute() { $this->password = Hash::make($this->password); }
still can't change the password, but the other field
result: Before Save: $2y$10$47fSa//7DFWx0cv61PypZeCaACf4r.OxdrtThG.TD1kkS7HJIFB1m After Save: $2y$10$3qCjAitWwGqqQSaKgTRK6O9/RolQ7Ep/uEVmQHplNTJKF6dXITb4Gobject(User)#201 (21) { ["table":protected]=> string(4) "user" ["timestamps"]=> bool(true) ["connection":protected]=> NULL ["primaryKey":protected]=> string(2) "id" ["perPage":protected]=> int(15) ["incrementing"]=> bool(true) ["attributes":protected]=> array(12) { ["id"]=> int(1) ["group_id"]=> int(1) ["username"]=> string(5) "admin" ["email"]=> string(20) "[email protected]" ["password"]=> string(60) "$2y$10$47fSa//7DFWx0cv61PypZeCaACf4r.OxdrtThG.TD1kkS7HJIFB1m"
Try it without setPasswordAttribute. Try the example exactly as I have, just to be sure it is not your setPasswordAttribute method.
Thanks pickupman, it's ok now. i dont know why seypasswordattribute dont work when i updated password
so if i need login,register, update which about password field, i just use Hash::make to do it? DONT USE setPasswordAttribute() ?
have other suggests ?
It's because your mutator is wrong and should look like this to work:
public function setPasswordAttribute($plain)
{
$this->attributes['password'] = Hash::make($plain);
}
pickupman said:
What happens if you try:
Route::get('/', function() { $user = User::find(39); echo ' Before Save: ' . $user->getAuthPassword(); $user->email = '[email protected]'; $user->password = Hash::make('aaaaaaaa'); $user->save(); echo ' After Save: ' . $user->getAuthPassword(); dd($user); });
The User model encrypts your password when saving it to the database, your password will not be in plain text.
Is this an appropriate way ?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community