recovery men recovery men - 1 year ago 87
PHP Question

Password should not be update if user not give any value in password field laravel 5.3

I am working on edit profile and i want that password should not be update if user not give any values in password field now if user not enters any value then password update automatically

Here is my method

$this->validate($request, [
'name' => 'required|max:255',


$user = User::findOrFail($id);
$input = $request->all();
'name' => $request->input('name'),
'password' => bcrypt($request->input('password')),
'def_timezone' => $request->input('def_timezone'),
'address_line_1' => $request->input('address_line_1'),

session()->flash('msg',trans('successfully Updated.'));

I have many Questions like this but not understand how to do Please Help to fix the issue Thanks

Answer Source

You can do this:

'password' => $request->password ? bcrypt($request->password) : $user->password,

Also, you can use update() method instead of fill() and save(). With this approach empty values will be ignored:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download