我有以下资源路线:
Route::resource('/evenementen', 'EventController');
根据以下命令(php artisan route:list):
POST | admin/evenementen | evenementen.store | App\Http\Controllers\EventController@store | web,App\Http\Middleware\isAdmin |
GET|HEAD | admin/evenementen | evenementen.index | App\Http\Controllers\EventController@index | web,App\Http\Middleware\isAdmin |
GET|HEAD | admin/evenementen/create | evenementen.create | App\Http\Controllers\EventController@create | web,App\Http\Middleware\isAdmin |
GET|HEAD | admin/evenementen/{evenementen} | evenementen.show | App\Http\Controllers\EventController@show | web,App\Http\Middleware\isAdmin |
DELETE | admin/evenementen/{evenementen} | evenementen.destroy | App\Http\Controllers\EventController@destroy | web,App\Http\Middleware\isAdmin |
PUT|PATCH | admin/evenementen/{evenementen} | evenementen.update | App\Http\Controllers\EventController@update | web,App\Http\Middleware\isAdmin |
GET|HEAD | admin/evenementen/{evenementen}/edit | evenementen.edit | App\Http\Controllers\EventController@edit | web,App\Http\Middleware\isAdmin
我应该有那些路线。存储,建立索引以及创建路线和方法都在起作用。其余的路线不是。
如果我进入/ admin / evenementen / 1 / edit,则会显示“找不到页面”错误。如果使用以下格式POST到/ admin / evenementen / 1,也会发生这种情况:
<form id="frm-delete" action="{{ URL::asset('admin/evenementen/'.$event->id) }}" method="POST">
{{ csrf_field() }}
@method('DELETE')
<button type="submit" class="dropdown-item">
Verwijderen
</button>
</form>
在EventController中,我具有以下应与路线相对应的方法:
public function index() {..}
public function destroy($id) {..}
public function show($id) {..}
public function create() {..}
public function store(CreateEventRequest $request) {..}
public function edit($id) {..}
一直在搜索很多东西,找不到我做错了什么。真的希望有人能帮助我。
答案 0 :(得分:1)
我无法全神贯注,并且已经认为这很简单。
如果创建资源,则控制器方法不希望ID,而需要模型。所以就事件而言
public function destroy($id) {..}
应该是:
public function destroy(Event $event) {..}
真的希望这也可以帮助其他人