Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Dean's avatar
Level 7

request()->validate vs $this->validate

Just want to know what differences there are between request()->validate and $this->validate is when put in a controller?

I believe the later returns only the validated fields, what about the former?

0 likes
3 replies
tykus's avatar

The difference is since Laravel 5.5, the validate method is available on the Illuminate\Http\Request object (request()->validate) rather than previously via the ValidatesRequests trait that was mixed into Controllers ($this->validate).

The newer implementation also functions as a filter similar to request()->only(), returning only the request fields that are specified in the rules array. This means you need to add a key/value pair with an empty value to pass the field through

$data = request()->validate([
    'name' => 'required',
    'email' => 'required',
    'age' => ''
]);

$user = User::create($data);
3 likes
Dean's avatar
Level 7

If what you're saying is true then they're basically the same, because the controller method also returns only the request fields that are specified in the rules array.

tykus's avatar
tykus
Best Answer
Level 104

Only, since 5.5 it does.

Please or to participate in this conversation.