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

Array query params redirection test[] to test[0] #2222

Open
ThibaudDauce opened this issue Jan 31, 2025 · 1 comment
Open

Array query params redirection test[] to test[0] #2222

ThibaudDauce opened this issue Jan 31, 2025 · 1 comment

Comments

@ThibaudDauce
Copy link

Version:

  • @inertiajs/vue3 version: 2.0.3

Describe the problem:

Inertia replaces array query params with number keys: it redirects from http://localhost:8000/?test[]=foobar to http://localhost:8000/?test[0]=foobar

Steps to reproduce:

laravel new test
# Select Breeze -> Inertia Vue
cd test
npm install
composer run dev

Visit http://localhost:8000/?test[]=foobar.

Inertia redirects to http://localhost:8000/?test[0]=foobar

@Verox001
Copy link

Verox001 commented Feb 1, 2025

This is actually a problem with Laravel itself, as Laravel retrieves query parameters like this:

$test = $_GET['test'];

While $_GET looks something like that:

Array
(
    [test] => Array
        (
            0 => foobar
        )
)

The reason for the index 0 being added is quite simple:
PHP only works with arrays that have keys. If no keys are found, PHP will automatically add them, starting from 0.

For example, if you pass the query parameters:
?test[0]=foo&test[]=bar,
it will redirect back as:
?test[0]=foo&test[1]=bar.

This won't be solved by Inertia as it's just a PHP convention.
Maybe you can let me know what you're trying to achieve, and we can find another way or a workaround.

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

No branches or pull requests

2 participants