调用未定义的方法 Laravel\Lumen\Routing\Router::where()

Call to undefined method Laravel\Lumen\Routing\Router::where()

如何在 Lumen

中使用 where 方法
Route::get('/talent/{id}', 'TalentController@talent')->where('id', '[0-9]+');

给我这个错误:

(1/1) FatalThrowableError
Call to undefined method Laravel\Lumen\Routing\Router::where()

使用 php 7"laravel/lumen-framework": "5.5.*"

Lumen 使用的路由器与 Laravel 不同。

对于 Lumen,正则表达式约束直接在路由参数定义中。您的代码看起来像:

$router->get('/talent/{id:[0-9]+}', 'TalentController@talent');

您可以在 the documentation here 中阅读有关 Lumen 路由和约束的更多信息。