Is there a way of condensing the following code into a single update()?:
$this->validate(request(), [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users,email,'.$id,
'password' => 'nullable|string|min:6|confirmed',
'timezone' => 'required|timezone',
]);
$user = User::findOrFail($id);
$user->update(request()->all());
if (!empty(request()->input('password'))) {
$user->update(['password' => bcrypt(request()->input('password'))]);
}
I want to get rid of the conditional statement for updating the password because I am using a mutator to bcrypt it automatically now. Is there a method like request()->allNotNull()?
bcrypt()your password? Also which version of Laravel are you using?