inertia
inertia copied to clipboard
Remove empty payload from GET requests
Currently all Inertia GET requests have Content-Type: application/json header applied because empty object is passed as a payload. Axios sees an object and sets content type to application/json even though request body is empty.
This is an issue because Laravel interprets these requests differently than regular GET request. See here
One example where this is a problem - for example I have GET route and I want to add or update some query parameters in current request using request()->merge(['foo' => 'bar'])
When running request()->query() I expect to get foo parameter back since it is a GET request. Instead I get nothing. This is because merge runs on json input source instead of query. See here and here
Setting data to null is enough for Axios to ignore payload.
Here is another case
->get(..) method is broken on any request instance derived from original request.
$request = Request::createFrom(request());
request()->merge(['foo1' => 'bar']);
$request->merge(['foo2' => 'bar']);
var_export(request()->get('foo1'));
var_export($request->get('foo2'));
// GET request without content-type "application/json" header
'bar'
'bar'
// GET request with content-type "application/json" header
'bar'
NULL
For example this breaks spatie/laravel-query-builder package since it uses ->get() method internally to get filter/sorting params from query.