I noticed that in your closure you have a / before your route, but you don't have that when you use a controller! I don't know if that's the issue though...
Lumen routing parameters not (always) passed
Hi,
I'm having some trouble with Lumen's routing. I'm trying to capture the uri using regex in a route.
When I try to pass the captured data to a controller method, the variable is empty, yet when I do the same using a closure, the variable shows as expected. Here's the code:
This works:
$app->get('/{categoryUrlPath:[a-zA-Z0-9\-\/]+}', function($categoryUrlPath) {
echo $categoryUrlPath;
});
This doesn't work:
$app->get('{categoryUrlPath:[a-zA-Z0-9\-\/]+}', ['uses' => 'App\Http\Controllers\FrontController@showSearch']);
and
public function showSearch($categoryUrlPath = null) {
return $categoryUrlPath;
}
Debugging the controller with
print_r(app('request')->route());
shows that the variable is there:
Array ( [0] => 1 [1] => Array ( [uses] => App\Http\Controllers\FrontController@showSearch ) [2] => Array ( [categoryUrlPath] => this/is/a/captured/uri ) )
But still it isn't passed as $categoryUrlPath
Any help appreciated - I'm puzzled. Also, I realise the are other (easier) ways to capture just the URI but I have a specific reason for doing it this way and, besides, I'd like to understand what I'm doing wrong with the router here.
Thanks!
I just tried your code its the '= null' that's causing the problem (no idea why)
public function showSearch($path) [} // this works
public function showSearch($path = null) [} // this doesn't
Please or to participate in this conversation.