Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use capture to populate global request with json array #883

Merged
merged 1 commit into from
May 7, 2024

Conversation

krowinski
Copy link
Contributor

To replicate :

Create route with FrankenPHP server.

Route::post('/test', static function (Request $request) {
    return new JsonResponse($request->get('key'));
});

POST json

curl --location 'localhost/test/' \                                                                                                                               
--header 'Content-Type: application/json' \
--data '{"key":"value"}'

Expected "value"
Current "{}"

Laravel is using $response = $kernel->handle($request = Request::capture())->send(); in index.php but FrankenPhpClient is just doing Request::createFromGlobals() and its not passing by \Illuminate\Http\Request::createFromBase that populate request using incoming json values using this code fragment.

       if ($newRequest->isJson()) {
            $newRequest->request = $newRequest->json();
        }

Request::capture is using createFromBase that checks is request is json and replace request with json array

``` 
       if ($newRequest->isJson()) {
            $newRequest->request = $newRequest->json();
        } 
```

and later when in controller you can use request->get('some-json-key') to get value as its a default laravel behavior [check index.php:53]
@taylorotwell taylorotwell merged commit 61a3e69 into laravel:2.x May 7, 2024
27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants