Description
Laravel Version
10.16.1
PHP Version
8.2.7
Database Driver & Version
No response
Description
Since v10.16.1 we seem to be getting different values than previous versions when using $request->get()
. We were debugging with $request->all()
but noticed that get() is returning values compared to all() when retrieving an object.
Tested in Laravel 8.83.27, 9.52.10, 10.15.0 and 10.16.0 - we get the same results, here is a stripped back example:
More screenshots here
However in Laravel 10.16.1, we're getting the following result with identical code:
We are currently changing how we are handling requests in this legacy application, but essentially when using the following code, 10.16.1 causes Illuminate\Support\Exceptions\MathException
exception while using attribute casting to a decimal (even passes validation). This seems to be since the value is now an empty string instead of null.
$object = $request->get('object');
$myModel->amount = $object['amount'];
$myModel->save();
$object->instance = $myModel;
Whilst we are changing the way request values are retrieved, we are sure we aren't the only ones that has/will come across this, reporting just incase. We tracked this down to pull request #47838 - $newRequest->request = new InputBag($newRequest->json()->all());
Steps To Reproduce
Add the following to web.php:
Route::post('/test', function () {
Request::validate(['object.amount' => ['decimal:2', 'nullable']]);
$object = Request::get('object');
dd(Request::all(), Request::get('object'), App::version(), $object['amount']);
});
Do a post request to /test
with the following json:
{
"object": {
"name": "test",
"amount": ""
}
}