I'm using Laravel 8, and in the Laravel document, I see this line of code for retrieving the validated input data then using form requests.
// Retrieve the validated input data...
$validated = $request->validated();
But if I clear this line, everything is fine! So, What is the reason for this retrieval?
The
->validated()method returns information from your request that actually underwent validation. Let's use a quick scenario:If you have the following rules:
Then, after running validation, calling
->validated()will return the following:Notice how
middle_nameis missing? It was not included in the validation rules, and as such is stripped out.You can read the full documentation here:
https://laravel.com/docs/8.x/validation#working-with-validated-input
Note: If you're validating everything in your
$request, i.e.first_name,middle_nameandlast_name, then you can use$request->validated(),$request->input()or$request->all(); they will all be the same.