Named parameters are usually executed as route segments, but without explicit naming. So, for example, you could something like this:
Route:get('test/{id?}/{page?}/{opt?}', function ($id = null, $page = null, $opt = null) {
$id , $page and $opt all optional here, as defined ? in segment definitions, and the fact that they have default values ββin the function. However, you will notice something like a problem here:
- They should appear in the url in the correct order
- Only
$opt really optional, $page should be specified if $opt is, and $id should be if $page is
This limitation is due to the fact that Laravel maps named segments to function / method parameters. Theoretically, you could implement your own logic to do this work:
Route:get('test/{first?}/{second?}/{third?}', function ($first = null, $second = null, $third = null) { if ($first) { list($name, $value) = @explode('=', $first, 2); $$name = $value; } if ($second) { list($name, $value) = @explode('=', $second, 2); $$name = $value; } if ($third) { list($name, $value) = @explode('=', $third, 2); $$name = $value; }
Not that it was a very naive decision, relying on blind blasting on = , as well as on setting the name of an arbitrarily entered variable (which, obviously, requires trouble). You should add additional verification to this code, but it should give you an idea of ββhow to overcome the above two problems.
It should probably be noted that this seems like the βright wayβ to perform routing and URIs in Laravel, so if you really don't need this functionality, you should rethink how you configure these URIs so that the Laravel Frame is more configured for.