我正在尝试使用Laravel 5框架构建我们网站的新版本。
问题是,我们现在有以下网站结构(这可能不会改变):
- domain.com/[productname]<-动态的
- domain.com/[categoryname]<-动态的
- domain.com/some-static-page1
- domain.com/some-static-page2
在我们的数据库中,我们有一个不同产品名称和不同类别的列表。
我想将[productname]路由到productController,将[categoryname]路由到categoryController。但是,因此,我需要在每个请求中查询我们的数据库,看看URL参数是产品还是类别。
有什么办法让我走上正确的方向吗?
提前感谢!
我认为这将是最好的方法:
路线:
Route::get('/cat={name}', 'CatagoryController@cataFind');
Route::get('/prod={name}', 'ProductController@prodfind');
控制器:
public function cataFind($name){
//get all the rows with that cata
$catas = Product::where('cata', $name)->get();
return view('cata')->with('catas', $catas);
}
public function prodFind($name){
//get all the rows with that prod name
$prod = Product::where('name', $name)->get();
return view('prod')->with('prod', $prod);
}
如果你需要了解正在发生的事情,请发表评论,我会更新帖子。但这是你应该走的路,我应该想想!