Best practices to handle the Laravel request validation.
Add caption |
It looks little messy and hard to manage if there are multiple fields coming as a input. So we can resolve this by moving all this mess into request file. How?
Open project directory in terminal and run
- php artisan make:request StoreMyRequests
StoreMyRequests.php. Now open this file and move validation code into this and it will looks like:-
Now, Use these validations in controller like:-
Now, All mess moved from controller and it increase the reuse ability of code. You can use same rules at multiple places.
Comments
Post a Comment