I am trying to create a function to add users to my system using name , email, start_date and password.
I can save all the data to the database row but cannot for the life of me hash the password using bcrypt, it should be relatively easy but i am missing something.
public function store(UserRequest $request, User $user)
{
$user->create($request->all());
return redirect('admin/users');
}
As you can see I have a store function but need to add the password hashing to it. any pointers please?
Some people don't like having to specify all the attributes. If you like to keep your way of doing things where you just put $request->all(), then keep that and do this instead. Go to your User model and add this:
public function setPasswordAttribute($password) {
$this->attributes['password'] = bcrypt($password);
}
This will automatically hash the password whenever you are setting the user's password.
Thank you all for your solutions, I went with the first model based solution as this fitted best with how I wanted the controller and model used, I also learned something from all the solutions, so once again thanks for your time it so very much appreciated.