How to Usage of Request Class Laravel
Hello, Artisans, welcome to the 5th chapter of being an Artisanary. Laravel is a popular PHP framework that offers a range of features and tools to simplify web development. One of the key features of Laravel is its ability to handle form validation. Laravel provides various ways to validate forms, and one of the most popular ways is by using the Form Request Class. So if you already complete the previous chapters/sections, then you're good to go, if not my recommendation would be please complete the previous chapters. Because we'll use the same old repository that we use from
Note: Tested on Laravel 10.0
- Create a Form Request Class and Define validation rules
- Use Form Request Class in Controllers
- Customize error messages in Form Request Class
Create a Form Request Class and Define validation rules
So for creating a form request class, first we've to fire the below command in the terminal. But as we already said that we'll use our old repository. Because later that we'll use it for our real life works. So, fire the below command
It'll create a file under app/Http/Requests/BlogRequest.php, open the file and you can see the file looks like below:
For customizing error messages, the request class provides another method called messages() where we can define messages for each rules. Look at the below source code.
In this way, we can customize any error messages.
0 Comments
CAN FEEDBACK
Emoji