Symfony Forms auto binds to a model class if available.
This causes issues when the form has fields that are not in the model.
Examples
E.g. special behaviour required for Update password form. app/Forms/UpdatePasswordForm.php
if ($form->isSubmitted() && $form->isValid()) {
$new_password = $user->new_password;
// Get rid of junk data from user model
unset($user->new_password);
unset($user->new_password_confirmation);
unset($user->current_password);
// Hash and save new password.
$user->password = Hash::make($new_password);
$user->save();
return redirect()->route('account.profile.show', $user)
->with('status', 'Your password has been successfully updated.');
}
Similar issue if we have things like HTML blocks, these try to save to the model if passed.
See https://github.com/barryvdh/laravel-form-bridge
Also see unmapped fields: https://symfony.com/doc/current/forms.html#form-unmapped-fields
Expected behavior
Review this and see whether it makes sense to skip additional fields from model binding, if possible. Otherwise don't bind models in these instances where we need more control over the form.
Symfony Forms auto binds to a model class if available.
This causes issues when the form has fields that are not in the model.
Examples
E.g. special behaviour required for Update password form. app/Forms/UpdatePasswordForm.php
Similar issue if we have things like HTML blocks, these try to save to the model if passed.
See https://github.com/barryvdh/laravel-form-bridge
Also see unmapped fields: https://symfony.com/doc/current/forms.html#form-unmapped-fields
Expected behavior
Review this and see whether it makes sense to skip additional fields from model binding, if possible. Otherwise don't bind models in these instances where we need more control over the form.