Modifying Laravel's Request Object

Symfony had changed how requests can be modified in incoming middleware.

The recommended way to achieve this in Laravel has been:

            $request->request->add(["scope" => data_get(
                $settingsDetails,
                "clientScopes.{$client?->getKey()}",
            )]);

or for JSON:

            $request->json()->add(["scope" => data_get(
                $settingsDetails,
                "clientScopes.{$client?->getKey()}",
            )]);

That is no longer sufficient as of symfony/psr-http-message-bridge version 2.3, and you must now regenerate the request object and update the content (see the last parameter).

            $request->initialize(
                $request->query->all(),
                $request->request->all(),
                $request->attributes->all(),
                $request->cookies->all(),
                $request->files->all(),
                $request->server->all(),
                json_encode($request->json()->all()),
            );

I suspect this is a bug in the Symfony package, but for now this is the recommended solution.