inertia icon indicating copy to clipboard operation
inertia copied to clipboard

Get method Array serialization

Open Tofandel opened this issue 3 years ago • 0 comments

Versions:

  • @inertiajs/inertia version: 0.11.0

Describe the problem:

When using the get method without formData and passing an array of objects, the serialization of the array is wrong

Steps to reproduce:

https://codesandbox.io/s/axios-forked-dmrd6p?file=/src/index.js:224-284

Inertia.get("/posts", {
    arr: [{test: 1, test2: 2}]
});

Look at the request produced which will be /posts?arr[][test]=1&arr[][test2]=2 but should be /posts?arr[0][test]=1&arr[0][test2]=2

The current url in php will produce

[
    'arr' => [['test' => '1'], ['test2' => '2']]
]

Instead of the expected

[
    'arr' => [['test' => '1', 'test2' => '2']]
]

It's possible to get around the issue using the qs option, but I believe it would be best to make it the default as without it, the behavior is not correct and this option is not documented

Inertia.get("/posts", {
    arr: [{test: 1, test2: 2}]
}, {queryStringArrayFormat: 'indices'});

Tofandel avatar Mar 18 '22 13:03 Tofandel