Laravel资源调用错误的方法

时间:2017-09-21 09:26:36

标签: php laravel

我在Laravel工作几个小时后就疯了。

这是我的web.php文件:

// Admin
Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'admin'], 'namespace' => 'Admin'], function() {

  Route::resource('cities', 'CitiesController');
  Route::resource('stores', 'StoresController');

});

我正在访问http://localhost:3000/admin/cities/create,我从show方法收到错误!为什么网址调用show方法而不是create?如果我删除Route::resource并替换为详细路由,为什么会有效呢?那太疯狂了。

enter image description here

更新

我的route:list

|        | GET|HEAD  | admin                     | admin            | App\Http\Controllers\Admin\DashboardController@index                   | web,auth,admin |
|        | GET|HEAD  | admin/cities              | cities.index     | App\Http\Controllers\Admin\CityController@index                        | web,auth,admin |
|        | POST      | admin/cities              | cities.store     | App\Http\Controllers\Admin\CityController@store                        | web,auth,admin |
|        | GET|HEAD  | admin/cities/create       | cities.create    | App\Http\Controllers\Admin\CityController@create                       | web,auth,admin |
|        | GET|HEAD  | admin/cities/{city}       | cities.show      | App\Http\Controllers\Admin\CityController@show                         | web,auth,admin |
|        | PUT|PATCH | admin/cities/{city}       | cities.update    | App\Http\Controllers\Admin\CityController@update                       | web,auth,admin |
|        | DELETE    | admin/cities/{city}       | cities.destroy   | App\Http\Controllers\Admin\CityController@destroy                      | web,auth,admin |
|        | GET|HEAD  | admin/cities/{city}/edit  | cities.edit      | App\Http\Controllers\Admin\CityController@edit                         | web,auth,admin |
|        | GET|HEAD  | admin/stores              | stores.index     | App\Http\Controllers\Admin\StoreController@index                       | web,auth,admin |
|        | POST      | admin/stores              | stores.store     | App\Http\Controllers\Admin\StoreController@store                       | web,auth,admin |
|        | GET|HEAD  | admin/stores/create       | stores.create    | App\Http\Controllers\Admin\StoreController@create                      | web,auth,admin |
|        | GET|HEAD  | admin/stores/{store}      | stores.show      | App\Http\Controllers\Admin\StoreController@show                        | web,auth,admin |
|        | DELETE    | admin/stores/{store}      | stores.destroy   | App\Http\Controllers\Admin\StoreController@destroy                     | web,auth,admin |
|        | PUT|PATCH | admin/stores/{store}      | stores.update    | App\Http\Controllers\Admin\StoreController@update                      | web,auth,admin |
|        | GET|HEAD  | admin/stores/{store}/edit | stores.edit      | App\Http\Controllers\Admin\StoreController@edit                        | web,auth,admin |

1 个答案:

答案 0 :(得分:-1)

制作这样的展示店铺路线:

Route::get('/store/{store}', 'StoresController@show')->name('stores.show');