Route::group(['prefix' => 'commodities'], function(){
Route::get('commodities', [
'as' => 'showCommodities', 'uses' => 'commodityController@showAll'
]);
Route::get('{id}', [
'as' => 'showcommodity', 'uses' => 'commodityController@show'
]);
Route::get('add', [
'as' => 'addcommodity', 'uses' => 'commodityController@create'
]);
Route::post('update', [
'as' => 'updatecommodity', 'uses' => 'commodityController@update'
]);
Route::post('destroy', [
'as' => 'destroycommodity', 'uses' => 'commodityController@destroy'
]);
Route::post('add', [
'as' => 'storecommodity', 'uses' => 'commodityController@store'
]);
});
我在这里粘贴了commodityController代码http://pastebin.com/bWrdVhsv
一切都有效,除了GET路线商品/添加.我总是得到一个白页.我的调试设置为TRUE,我有正确的刀片.
我在这里错过了什么吗?
解决方法:
问题是您的路线顺序.
将添加路线移动到捕获所有{id}路线上方.
Route::group(['prefix' => 'commodities'], function(){
Route::get('commodities', [
'as' => 'showCommodities', 'uses' => 'commodityController@showAll'
]);
Route::get('add', [
'as' => 'addcommodity', 'uses' => 'commodityController@create'
]);
Route::get('{id}', [
'as' => 'showcommodity', 'uses' => 'commodityController@show'
]);
Route::post('update', [
'as' => 'updatecommodity', 'uses' => 'commodityController@update'
]);
Route::post('destroy', [
'as' => 'destroycommodity', 'uses' => 'commodityController@destroy'
]);
Route::post('add', [
'as' => 'storecommodity', 'uses' => 'commodityController@store'
]);
});
Laravel将从头到尾浏览您的routes.PHP文件.以下路线基本上是一个全部.
Route::get('{id}', [
'as' => 'showcommodity', 'uses' => 'commodityController@show'
]);
这意味着它将捕获所有与模式匹配的URL的GET请求:
/商品/一些实物-的字符串.
由于/ commodities / add uri与上述模式匹配,它将使用该路由,因为它首先出现在routes文件中.