I have redacted the guard with a generic "foo" for privacy.
Dec 2, 2025
5
Level 4
Alternative way to achieve this kind of validation
Hello,
don't kill me please. I tried the Laravel "validation" style but I'm unable to get the same result for the following (dirty) code.
public function update(Request $request)
{
if (empty($request->current_password)) {
return back()->withInput()
->with('error', 'lang.profile.settings.preferences.password.current_password.error.required')
->with('hasLinkBack', true);
}
if (empty($request->new_password)) {
return back()->withInput()
->with('error', 'lang.profile.settings.preferences.password.new_password.error.required')
->with('hasLinkBack', true);
}
if (strlen($request->new_password) < 8) {
return back()->withInput()
->with('error', 'lang.profile.settings.preferences.password.new_password.error.min')
->with('hasLinkBack', true);
}
if (empty($request->new_password_verify)) {
return back()->withInput()
->with('error', 'lang.profile.settings.preferences.password.new_password_verify.error.required')
->with('hasLinkBack', true);
}
if ($request->new_password !== $request->new_password_verify) {
return back()->withInput()
->with('error', 'lang.profile.settings.preferences.password.new_password_verify.error.different')
->with('hasLinkBack', true);
}
// Check current password
if (!Hash::check($request->current_password, auth('foo')->user()->password)) {
return back()->withInput()
->with('error', 'lang.profile.settings.preferences.password.current_password.error.incorrect')
->with('hasLinkBack', true);
}
// Update password
auth('foo')->user()->update(['password' => Hash::make($request->new_password)]);
return redirect()
->route('my.profile.settings.preferences.password.edit')
->with('success', 'lang.profile.settings.preferences.password.updated_successfully');
}
Basically I want to flash one error at time. Could you please suggest a cleaner approach?
Thanks Simon
Please or to participate in this conversation.