Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

Route parameters and route priorities

I have list of tables which are generic so I have a route with parameter:

Route::get('/tables/{table_name}', [TablesController::class, 'show_table']);

But some tables are specific so I have their routes explicitly:

Route::get('/tables/unique_table', [TablesController::class, 'show_unique_table']);

In such case, do I have to keep the routes with explicit table names above the ones with parameters? Because I know that it will lookup the first match. I just don't want to rely on the order of the routes. So maybe there is a better way to make it match so that the order won't affect anything?

0 likes
5 replies
tykus's avatar

do I have to keep the routes with explicit table names above the ones with parameters?

Yes, they will be matched first.

I just don't want to rely on the order of the routes.

Too bad...

So maybe there is a better way to make it match so that the order won't affect anything?

Not without some lookup table to match the explicit routes.

1 like
Ligonsker's avatar

Thanks, and is this situation normal? I just feel that if I reached this point where I need to rely on the order then something is wrong with my code, but might be just my feeling?

tykus's avatar
tykus
Best Answer
Level 104

@Ligonsker

Thanks, and is this situation normal?

Yes.

I just feel that if I reached this point where I need to rely on the order then something is wrong with my code, but might be just my feeling?

This is how we ensure the Request is correctly routed - higher specificity routes first, then generic routes which catch anything not already matched (for a given URI schema)

1 like

Please or to participate in this conversation.