2017-05-29 175 views
1

我是Laravel的新增内容。 路线/ api.php我写了这个功能Laravel路由路由::路由内的资源::组

Route::group(['namespace' => "Catalogue"],function(){ 
    Route::resource('product','Product'); 
}); 

我创建了一个资源控制器:

app/Controllers/Catalogue/Product.php 

这是我的索引方法:

public function index() 
    { 
     $pdo = DB::select('select count(*) from offers'); 
     return $pdo; 
    } 

我试图让来自url的索引方法的结果:

http://localhost:8000/api/Catalogue/product

但是,这导致404 not found。 注意:这部分网址没有问题http://localhost:8000/api

+0

'路由组允许您跨大量路由共享路由属性,如中间件或名称空间,而无需在每条单独路由上定义这些属性。 ''产品'是中间件还是命名空间? –

回答

1

您正在碰错uri。 检查http://localhost:8000/api/product

组路径中的命名空间意味着您将一个命名空间分配给一组控制器。正如你在这里可以看到https://laravel.com/docs/5.4/routing#route-group-namespaces。它与路线无关。

在这里你可以看到其他路线,当你在控制器中制作它们时。 https://laravel.com/docs/5.4/controllers#controllers-and-namespaces

+0

谢谢,但你能告诉我,如果我的URI是这样的:http:// localhost:8000/api/Catalog/Product,http:// localhost:8000/api/Catalog/Brand等等, ,那么我应该如何将他们分组。 – Jagrati