Skip to content

Conversation

michael-mcmullen
Copy link

Through some debugging on the discord channel we found that Lumen does care about what you name your parameters whereas Laravel does not. It would be nice to have a notice in there so it is specified for those coming from Laravel and don't match up their parameter names with variables.

Simple test cases

Url: test/12/2/6/1983

$router->get('/test/{id}/{day}/{month}/{year}', function ($id,$day,$month,$year) {
    echo "$id - $day - $month - $year";
});

Return: 12 - 2 - 6 - 1983

versus

Url: test/12/2/6/1983

$router->get('/test/{anotherId}/{day}/{month}/{year}', function ($id,$day,$month,$year) {
    echo "$id - $day - $month - $year";
});

Return: 2 - 6 - 1983 - 12

Added notes for parameter matching
@michael-mcmullen
Copy link
Author

Not sure how to word it as testing it; All your URL parameters either need to match up to the function, or none of them need to match up in order for it to work.

*this does not work

$router->get('/test/{one}/{day}/{three}/{four}', function ($id,$day,$month,$year) {
    echo "$id - $day - $month - $year";
});

*this does work

$router->get('/test/{one}/{two}/{three}/{four}', function ($id,$day,$month,$year) {
    echo "$id - $day - $month - $year";
});

@taylorotwell
Copy link
Member

I believe this is already noted in docs.

@michael-mcmullen
Copy link
Author

From reading the documentation (routing) there are a few points but nothing specific about naming the parameters correctly and mismatched parameter names.

It talks about how you cannot have dashes (-) in your parameters. And that the given parameters will be automatically inserted into the url in their correct positions (possible this is a good spot for the warning?) Required Parameters

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