Tuesday, April 4, 2017

Laravel wildcard left side (beginning) of URI

The following is well-defined in the Laravel docs:

Route::get('/users/{userid?}', $callback);

But how do I handle a wildcard on the left hand side of a URI? I want the following routes to all be picked up by one statement:

/about-us
/en/about-us
/fr/about-us

Something like:

Route::get('{language_code?}/about-us', $callback);

However this results in an unresolved redirect, at least in the project I'm working on. In summary, how do I handle and optional left-hand wildcard in Laravel?



via Oliver Williams

Advertisement