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

[Proposal] Overriding routes by order of declaration. #17

Closed
jasonlewis opened this issue Jan 13, 2013 · 4 comments
Closed

[Proposal] Overriding routes by order of declaration. #17

jasonlewis opened this issue Jan 13, 2013 · 4 comments

Comments

@jasonlewis
Copy link
Contributor

When a route is added the name generated is appended with microtime(true). This will mean that the first route to be declared will always be given precedence. Should it not be the order in which the two identically named routes are defined.

Currently:

Route::get('/', function()
{
    return 'This one will be run.';
});

Route::get('/', function()
{
    return 'This does not work. The first route is used.';
});

This may be intentional but it makes it really hard to override a route.

@taylorotwell
Copy link
Member

Yeah, you're probably right. Will look into it.

@jasonlewis
Copy link
Contributor Author

It's a simple fix, just drop the microtime(true) off of the end of a generated route name. The Symfony routing component will drop an existing route name when adding a route so the route defined last will always have precedence.

I'll send a PR.

@taylorotwell
Copy link
Member

OK, Thanks.

@xxpepe84xx
Copy link

The overriding of routes don't work in every case. If the semantic is equal but the spelling is different the router use the first declared route.

Works:

Route::get('part1/{part2}/{part3}', function($part2, $part3)
{
    return 'This does not work. The second route is used.';
});

Route::get('part1/{part2}/{part3}', function($part2, $part3)
{
    return 'This one will be run.';
});

Fails:

Route::get('part1/{part2}/{part3}', function($part2, $part3)
{
    return 'This one will be run.';
});

Route::get('part1/{part4}/{part5}', function($part4, $part5)
{
    return 'This does not work. The first route is used.';
});

Fails:

Route::get('part1/{part2}/{part3}', function($part2, $part3)
{
    return 'This one will be run.';
});
Route::get('part1/test/test', function()
{
    return 'This does not work. The first route is used.';
});

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

3 participants