我试图让Laravel允许多路由到1个控制器。这是因为我想为多个项目使用我的代码。想象一下以下内容:Laravel中的动态/可变路由
// Routes to the products
Route::get('/products', '[email protected]');
Route::get('/products/{id}', '[email protected]');
Route::get('/products/{id}/{any}', '[email protected]');
和
// Routes to the products
Route::get('/items', '[email protected]');
Route::get('/item/{id}', '[email protected]');
Route::get('/item/{id}/{any}', '[email protected]');
这矫枉过正我看来 - 我试图创建一个自定义配置文件,并添加首选的URI
// custom config
return array(
'product_plural' => 'products',
'product_single' => 'product'
)
,并添加该到我的路线
// Routes to the products
Route::get(Config::get('myconfig.product_plural'), '[email protected]');
Route::get(Config::get('myconfig.product_single').'/{id}', '[email protected]');
Route::get(Config::get('myconfig.product_single').'/{id}/{any}', '[email protected]');
此结果为
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
这使我相信在路由时配置不可用。很显然,我做错了一件事,目前我有点茫然。如果任何人都能指引我正确的方向,我将非常感激。
运行'php artisan routes'来确保你有你期望的路线,如果你仍然有问题,你应该显示当你得到这个错误(你运行的网址)。 – 2014-11-08 17:38:29
谢谢@MarcinNabiałek - 这表明我在我的自定义配置文件中有错误 - 并且能够解决这个问题,现在一切都按照我想要的那样工作。 – jvv 2014-11-08 17:42:31