在RouteCollection中获取NotFoundHttpException

时间:2016-03-06 14:59:47

标签: php laravel laravel-5

我收到了这个错误:

NotFoundHttpException in RouteCollection.php line 161:

当我从我的模板发出此请求时:

<a href="{{ route('getprodpage', ['id' => $product->id, 'entity' => 'incentive']) }}">

这是我的routes.php

Route::get('getprodpage/{id}/{entity?}', [
    'as' => 'getprodpage', 'uses' => 'ProductController@countProductClicks'
]);

这有什么问题?

修改

这就是我对嵌套资源的处理方式:

routes.php文件

Route::get('product/{id}/entity/{entity}', [
    'as' => 'getprodpage', 'uses' => 'ProductController@countProductClicks'
]);

刀片模板请求:

<a href="{{ route('getprodpage', ['id' => $product->id, 'entity' => 'incentive']) }}">

2 个答案:

答案 0 :(得分:1)

不允许制作路线&#39; getprodpage / {id} / {entity?}&#39;

尝试: https://laravel.com/docs/5.1/controllers#restful-resource-controllers 例如:

Route::get('products/{id}', ['as' => 'ShowProduct', 'uses' => 'ProductController@show']);

Route::get('products/{id}/categories/{catId}', ['as' => 'ShowProductCategory', 'uses' => 'ProductCategoryController@show']);

然后在您的CategoryController @ show方法中,您将获得两个变量:

show($productId, $categoryId){

}

答案 1 :(得分:0)

缓存发生,

使用命令

php artisan route:clear