So I'm trying to match a simple route with laravel that looks something like
/ID-OPTIONAL/OPTIONAL2/
So in order to get the hyphen to be optional I needed to use laravels where function and did something like so:
Route::any('/{id}{param?}/{param2?}', 'SomeController@Index', function($id = 0, $param = null, $param2 = null){})
->where(array('id' => '\d+', 'param' => '[A-Za-z-_]+'));
Now visiting
/10-some-random-param/another-param
/10-some-random-param/
Works fine, but when I all of a sudden do
/10/another-param
I get a routing error. Now is it possible to route this in one route or am I forced to write another line in order to get the expected result. Or is this a bug with laravels routing?
Eh, so basically I went w/ the following
Route::any('/{id}/{optional?}', 'HomeController@Index', function($id, $optional) {})
->where(array('id' => '(\d+)-?([A-Za-z0-9-_]+)?'));
Which isn't what I really wanted since I have to split the id w/ another regex check in the actual controller
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community