【发布时间】:2020-04-21 04:58:49
【问题描述】:
我有一个网页,其中有产品和产品类别,我有很多页面可以显示数据,例如我在哪里显示属于某个类别的产品,我正在为如何处理这个问题而摸不着头脑。
//Uses ProductController, shows products
Route::get('/products/category/{id}', 'Web\ProductController@productsCategoryId');
//Uses ProductCategoryController, shows products too
Route::get('/product-category/{id}/products','Web\ProductCategoryController@productCategoriesIdProducts');
我有两条显示相同数据的路线,都显示属于一个类别的产品,我的心告诉我我应该在 ProductController 中选择第一个,因为我总是显示产品,产品本身就是主要参与者,但是我也看到了使用的第二种路由模式,然后我想到了第三种选择。
忘记详细路由和使用查询参数怎么样:
/products?category=1
Boom,afaik 如果我这样做,我的控制器中将有一个入口点,并且根据查询参数从该方法中,我将显示不同的页面,index.blade,show.blade,category.blade。
使用查询参数让我更好地理解/阅读网址,但我担心有一个带有一堆 if 条件的单一方法是解决这个问题的方法......
我愿意接受各种建议。
【问题讨论】: