gpt4 book ai didi

php - Laravel 资源调用错误的方法

转载 作者:可可西里 更新时间:2023-10-31 23:50:46 25 4
gpt4 key购买 nike

自从使用 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 方法中得到一个错误!为什么 URL 调用 show 方法而不是 create?为什么如果我删除 Route::resource 并替换为冗长的路由,它会起作用吗?太疯狂了。

enter image description here

更新

我的路线:列表:

|        | 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 |

最佳答案

像这样制作您的展示店路线:

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

关于php - Laravel 资源调用错误的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46340214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com