I'm currently running a Laravel 5.4 project which has lots of different forms.
Form Request Validations are in place for each.
Every form displays its validation errors under each of its fields.
From time to time, I am requested to remove/rename a field.
The problem I face arises if the form request validation rules for that field aren't removed accordingly. The form validation fails because of these rules and the form is displayed again with no tip of what went wrong.
In order to handle this situation, I thought to
Load an extended version of Illuminate\Validation\ValidationServiceProvider
This CustomValidationServiceProvider, would be calling a CustomValidator class with an overwrote passes method that would instantiate a CustomMessageBag that would
- Overwrite method get, maintain the existing behavior and add a way keep track of which fields have been called via the get method.
- Create a method to get fields that weren't accessed via the get method.
After this, I would be implementing an after middleware for every get route (probably only for forms routes), that would check if the errors variable isn't empty and there are any fields which haven't been got, which translates to displayed in this context and act accordingly.
All this seems a lot of trouble in order to handle these "forgotten" validation rules.
The question is, do you guys can point me to someone that handled this situation before and shared its way, or, you can hint me on how to accomplish this without all the classes extensions.
Edit: I understand and agree with some of the comments stating that tests would be the proper way to handle this, but that's an option I don't have at the moment. I need to have a way to know if a validation error wasn't displayed despite the fact that this may not be a recommended approach.