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

[9.x] Split parameters when using regex constraints #38890

Closed

Conversation

Juhlinus
Copy link

A small paper-cut that I've seen users ask about. The "solution" seems to be to explode the parameters by yourself. (See examples below)

Using this PR parameters containing / will be treated as multiple parameters and exploded into an array.

Assuming that the requested url is: http://localhost/one/two

routes/web.php

Route::get('/{any}', TestController::class)->where('any', '.*');

app/Http/TestController.php

class TestController
{
    public function __invoke($parameters)
    {
        dd($parameters); // Will dump ['one', 'two']
    }
}

Example 1
Example 2

@claudiodekker claudiodekker changed the title Split parameters when using regex constraints [9.x] Split parameters when using regex constraints Sep 21, 2021
@Krisell
Copy link
Contributor

Krisell commented Sep 21, 2021

This causes the same paper-cut issue in the other direction, i.e. if you want a single variable to contain the full string you now have to implode the array.

I don't know what is more common, but I use .* in a few places to catch / in a single route variable, but I have never wanted to split this.

@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions!

If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response.

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.

3 participants