Laravel’s Form Requests are a great way of removing validation logic from your controllers.
There are times were it can be useful to update or change the request data before it is passed to the validator for example formatting postcodes, removing invalid characters or providing default values to data.
The official documentation shows how we can perform additional logic after the rule sets have been run but not before hand.
Digging through the Form Request api there is mention of a method called
prepareForValidation which is an empty method that is called before the actual validation rules are run as can be seen in implementation:
So given that the method is empty how do we use it and go about updating the form request data?Continue reading