When I first started using Laravel 12, I often asked myself — should I validate inside the controller or use a FormRequest? Both methods work, but they have different use cases. In this article, I’ll clearly explain both approaches with examples, so you can easily decide the best way to handle Laravel 12 validation in your projects.
When working with Laravel 12, choosing between FormRequest and Controller validation can be confusing. In this guide, I’ll show you both methods with simple examples.
In Laravel 12, you can validate user input directly inside the controller like this;
public function store(Request $request)
{
$validated = $request->validate([
'name' => 'required|max:255',
'email' => 'required|email',
'password' => 'required|min:8',
]);
// Save the data
}
Pretty straightforward, right?
But as your application grows, it’s better to organize validations separately using FormRequest:
php artisan make:request StoreUserRequest
Then, inside your StoreUserRequest class:
public function rules()
{
return [
'name' => 'required|max:255',
'email' => 'required|email',
'password' => 'required|min:8',
];
}
And in the controller:
public function store(StoreUserRequest $request)
{
// Validation already handled!
// Save the data
}
Aspect | Controller Validation | FormRequest Validation |
---|---|---|
Best for | Small apps, quick validation | Large apps, reusable validation |
Readability | Gets messy if large forms | Clean and organized |
Reusability | Hard to reuse rules | Easy to reuse across controllers |
Testing | Harder | Easier and isolated |
Maintainability | Poor | Excellent |
In short, if you are building a small app or just quickly testing, validating directly in the controller works fine.
But if you want your Laravel 12 project to stay clean, scalable, and professional — using FormRequest is the best way to handle validation.
From my experience, FormRequest saves a lot of headache in big projects.
So whenever possible, I personally go with FormRequest for all serious Laravel 12 validation work!
FormRequest is a dedicated class where you define your validation rules separately from the controller. It helps keep your code clean and organized.
Yes, you can! Laravel 12 still supports validation inside controllers using $request->validate()
method.
For large or growing projects, yes. FormRequest keeps the controller clean and makes validation reusable and easier to test.
Use the command:
php artisan make:request MyFormRequest
Yes! Laravel automatically injects FormRequest classes into your controller methods, validating before your method logic runs.
For more detailed information, refer to the official Laravel documentation on validation.
You might also like: