在Laravel我的路线如下:
Route::resource('/admin/products/', 'ProductsController');
因此,如果我转到myapp.app:8000/admin/products/
,我会收到所有产品:
public function index()
{
$products = Product::all();
return View::make('products.index', compact('products'));
}
但是如果我去myapp.app:8000/admin/products/1
我有以下内容:
public function show($id)
{
return "Hi!";
}
我收到错误页面: NotFoundHttpException 。我做错了什么?
如果有帮助,我已为相关查询附加了php artisan routes
输出:
+--------+---------------------------------+-------------------------+-----------------------------------------+----------------+---------------+
| Domain | URI | Name | Action | Before Filters | After Filters |
+--------+---------------------------------+-------------------------+-----------------------------------------+----------------+---------------+
| | GET|HEAD admin/users/{month?} | | AdminController@users | admin | |
| | GET|HEAD admin/products | admin.products..index | ProductsController@index | admin | |
| | GET|HEAD admin/products/create | admin.products..create | ProductsController@create | admin | |
| | POST admin/products | admin.products..store | ProductsController@store | admin | |
| | GET|HEAD admin/products/{} | admin.products..show | ProductsController@show | admin | |
| | GET|HEAD admin/products/{}/edit | admin.products..edit | ProductsController@edit
| | PUT admin/products/{} | admin.products..update | ProductsController@update | admin | |
| | PATCH admin/products/{} | | ProductsController@update | admin | |
| | DELETE admin/products/{} | admin.products..destroy | ProductsController@destroy | admin | |
答案 0 :(得分:1)
看起来它与Laravel如何解析路线有关。将您的路线更改为:
Route::resource('admin/products', 'ProductsController');
Artisan的输出列表应该改为:
GET|HEAD admin/products/{products}