How to Hash user input password when using Form Validation in Form Request( Laravel 5)
In my Controller class
public function postAccountCreate(postRequest $request, User $user) {
$user->create($request->all());
}
this single line of code does almost all the work by validating and then saving all the user form inputs to the users table when creating account for a user.
However I couldn't figure out how and where to Hash the user password before saving it to the database table. Please help!
@pstephan1187 thank you this is a great point. Could you please explain it ? because I am new to laravel and need to understand things, copy pasting is not enough, I want to understand it that how setPasswordAttribute will be call when I add new user or update existing one.
I know this was a long time ago but for anyone coming across this, adding this method will prevent the built in Laravel password reset method from working. ResetsPasswords.php passes an encrypted password so the setter above will re-hash the new password.
Just had the same issue as @devdurbs, had a User::updating event which hashed the password automatically and was scratching my head why the password reset functionality wasn't working. Had to resort to putting the password hashing in the Controller.
I know this is probably too late. But the problem with @roulendz answer is that it breaks the password reset functionality provded by laravel's scaffolding.