Route::get('/products/{page?}', 'ProductController@index')->name('products');
Route::get('/products/{category}/{page?}', 'ProductController@indexCategory')->name('category.products');
我有两条这样的路线。 当我像这样拨打第二条路线时:
<a href="{!! route('category.products', ['category' => $category['translation']['en']['slug']]) !!}" class="list-group-item active">
它调用@index方法而不是@indexCategory。
idk为什么?
我想做
转到索引方法
/产品,/产品/ 2,产品/ 3
转到索引方法
/ products / new-collection,/ products / new-collection / 2, / products / new-collection / 3
答案 0 :(得分:1)
我认为您需要像这样更新路线。
Route::get('/products/{page?}', 'ProductController@index')->name('products');
Route::get('/products-category/{category}/{page?}', 'ProductController@indexCategory')->name('category.products');
因为命名约定与您的路线冲突。因此请确保路由URL是唯一的。
然后像这样呼叫您的路线
<a href="{!! route('category.products', ['category' => $category['translation']['en']['slug']]) !!}" class="list-group-item active">
OR
如果您不想更改路线URL,请确保需要第二个渗透仪。不是可选的。