How do I get ONLY the validated data from a laravel FormRequest?
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Handling form data in your Laravel applications can be done with FormRequests - which provide an elegant way to validate and sanitize user input. However, accessing the requested data without retrieving additional fields or garbage data can be a bit tricky for developers new to this feature.
To get only validated data while avoiding unnecessary fields, you have various options: 1. Create a custom method in your FormRequest class to return only the required fields after validation and sanitization. This approach is relatively simple but involves writing custom code for each request:php
class PlanRequest extends FormRequest
{
// ...
public function validatedData()
{
$validated = parent::validated();
return array_only($validated, ['name', 'monthly_fee', 'transaction_fee', 'processing_fee', 'annual_fee', 'setup_fee', 'organization_id']);
}
}php
public function store(PlanRequest $request)
{
$validatedData = $request->validate(); // This will fail if the validation fails
dd($validatedData);
// This returns
[
'name' => 'value',
'monthly_fee' => '1.23',
'transaction_fee' => '1.23',
'processing_fee' => '1.23',
'annual_fee' => '1.23',
'setup_fee' => '1.23',
'organization_id' => null,
'foo' => 'bar', // This is not supposed to show up
];
}- Accessing Validated Data with getValidatedData():
- Accessing Validated Data with Model Bindings:
php
public function store(PlanRequest $request)
{
$validatedData = $request->getValidatedData(); // This will validate the request first and then return it
dd($validatedData);
// This returns
[
'name' => 'value',
'monthly_fee' => '1.23',
'transaction_fee' => '1.23',
'processing_fee' => '1.23',
'annual_fee' => '1.23',
'setup_fee' => '1.23',
'organization_id' => null,
'foo' => 'bar', // This is not supposed to show up
];
}array_only() as shown in option 1 to clean up the extra data.
php
public function store(Request $request)
{
$plan = Plan::create([
'name' => $request->input('name'),
'monthly_fee' => $request->input('monthly_fee'),
// ... Other fields you need
]);
}