Using laravel 5.8 / 6.0 , here is what I do (without a lot of extra code)
Step 1. Confirm
$data = request()->validate([ 'firstname' => ['required', 'string', 'max:255'], 'lastname' => ['required', 'string', 'max:255'], 'username' => ['bail', 'nullable', 'string', 'max:255', 'unique:users'], 'email' => ['bail', 'nullable', 'string', 'email:rfc,strict,dns,spoof,filter', 'max:255', 'unique:users'], 'new_password' => ['nullable', 'string', 'min:8'], 'confirm_new_password' => ['nullable', 'required_with:new_password', 'same:new_password'], 'current_password' => ['required', function ($attribute, $value, $fail) { if (!\Hash::check($value, Auth::user()->password)) { return $fail(__('The current password is incorrect.')); } }] ]);
Step 2: If Verification Passed
- Create an array by checking each input value (but not the value with the required tag when checking) for presence or zero OR do what you need.
For example:
if(request(input)){ $data += ['input' => request(input)]; }
- Updating the database using the created array
For example:
Auth::user()->account->update($data);
MR_AMDEV
source share