Description
Laravel Version
v10.27.0
PHP Version
8.2.11
Database Driver & Version
No response
Description
In version 9.32.0 and earlier, the validationData() method was called before the rules() method in the FormRequest, which provided the possibility of changing the data before being sent to rules().
framework/src/Illuminate/Foundation/Http/FormRequest.php
Lines 110 to 116 in aae3b59
As can be seen in the print below.
With the acceptance of PR [9.x] Introduce Laravel Precognition #44339, a "side effect" was introduced in the sequences in which methods are called.
From version 9.33.0 and later, the rules() method is being called before validationData(), not giving the possibility of making changes to the data before being sent to rules();
framework/src/Illuminate/Foundation/Http/FormRequest.php
Lines 110 to 122 in 13665b7
As can be seen in the print below.
I confirmed that the same code is in version 10 as well:
framework/src/Illuminate/Foundation/Http/FormRequest.php
Lines 117 to 133 in 6bfd755
Steps To Reproduce
Use the code below to notice that there is a change in the sequence in which the methods are executed:
// Route
Route::post('home', [HomeController::class, 'index']);
// Controller
class HomeController extends Controller
{
public function index(HomeTestRequest $request)
{
dd('HomeController');
}
}
// Form Request
class HomeTestRequest extends FormRequest
{
/**
* Get data to be validated from the request.
*
* @return array
*/
public function validationData()
{
dump('validationData');
$this->merge([
'foo' => 'bar',
]);
return $this->all();
}
protected function rules()
{
dump('rules');
dump($this->all());
return [];
}
}