Customising the inputs on Form Request in Laravel 6November 23, 2019
In this article I'm going to help you customize the inputs fields on the Form Request file in Laravel 6.x. Basically when you create a Laravel Form Request method, it'll have two functions.
authorize() method determines if the user is authorized to make this request and
rules() method holds the set of rules that we need to define as validation rules. However, there might be a situation where you would want to customize the input fields before they pass through the validation process. You can achieve this by calling the
First, lets create our form request file.
php artisan make:request StoreRequest
Now, the StoreRequest.php file will be placed under the app/Http/Requests folder.
Open up the StoreRequest.php file and add the validationData() method and customize your inputs before they pass in through validation like follows
In my example, I have an option where user will be uploading multiple images. On the validationData() method I'm just filtering out all the empty array and passing it through validation method.
Hope you find this useful. Happy Coding!