我是Laravel的新手。have /api.php我编写了这个函数
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。注意: url http://localhost:8000/api的这一部分没有问题。
发布于 2017-05-29 12:32:18
根据您的路由生成的链接是http://localhost:8000/api/product
如果需要链接为http://localhost:8000/api/Catalogue/product,那么将前缀添加到组中。
Route::group(['prefix' => 'Catalogue', 'namespace' => 'Catalogue'], function() {
Route::resource('product', 'Product');
});namespace只设置控制器的默认命名空间。prefix为组中的所有路由设置路由前缀。
发布于 2017-05-29 12:19:25
你打错了。检查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
https://stackoverflow.com/questions/44242054
复制相似问题