Skip to content

Potential breaking change for some cases in v10.16.1 regarding $request->get() #47878

Closed
@njones101

Description

@njones101

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:

image
More screenshots here

However in Laravel 10.16.1, we're getting the following result with identical code:

image

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": ""
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions