哈希laravel 4.5用户密码

I try to give users ability to change their password in profile page but when they change the password, password will not be hashed.

This is my update function in usercontroller:

public function update(Request $request, $id)
    {
        $user = User::find($id);
        $this->validate($request, array(
                'name' => 'required|string|max:255',
                'email' => [
                    'required','nullable','string','email','max:255',
                    Rule::unique('users')->ignore($user->id),
                ],
                'gender' => 'required|string',
                'password' => 'nullable|string|min:6|confirmed',
            ));

        $user = User::find($id);

        $user->name = $request->input('name');
        $user->email = $request->input('email');
        $user->gender = $request->input('gender');
        $user->password = $request->input('password');


        $user->save();

        Session::flash('success', 'Your information was successfully updated.');

        return redirect()->route('users.list');
    }

I solved the issue with using Trim. here is the code for those who need it:

if (trim(Input::get('password')) != '') {
            $user->password = Hash::make(trim(Input::get('password')));
        }