我在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
并替换为详细路由,为什么会有效呢?那太疯狂了。
更新
我的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 |
答案 0 :(得分:-1)
制作这样的展示店铺路线:
Route::get('/store/{store}', 'StoresController@show')->name('stores.show');