此路由不支持 DELETE 方法。支持的方法:GET、HEAD、POST
我正在使用Laravel 9.x 我的路线是
Route::middleware('verified')->group(function (){
Route::get('dashboard', function () {
return view('dashboard');
})->name('dashboard');
Route::resource('kullanicilar', UserController::class);
});
,我的控制器具有销毁方法
public function destroy($id)
{
echo 'destroy'.$id;
//User::find($id)->delete();
//return redirect()->route('kullanicilar.index')
// ->with('success','Kullanıcı başarı ile silindi.');
}
和我的user_index.blade.php,
<form method="POST" aciton="{{ route('kullanicilar.destroy',$user->id) }}" style="display:inline">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-sm btn-danger"><i class="fa fa-times"></i></button>
</form>
即使一切似乎都符合规则,我也会遇到此错误。
I'm using laravel 9.x
my route is
Route::middleware('verified')->group(function (){
Route::get('dashboard', function () {
return view('dashboard');
})->name('dashboard');
Route::resource('kullanicilar', UserController::class);
});
and my controller has destroy methods
public function destroy($id)
{
echo 'destroy'.$id;
//User::find($id)->delete();
//return redirect()->route('kullanicilar.index')
// ->with('success','Kullanıcı başarı ile silindi.');
}
and my user_index.blade.php
<form method="POST" aciton="{{ route('kullanicilar.destroy',$user->id) }}" style="display:inline">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-sm btn-danger"><i class="fa fa-times"></i></button>
</form>
even though everything seems to comply with the rules, I'm getting this error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的操作元素中存在拼写错误,导致表单被发布回与原始页面相同的路由;
注意
action
拼写错误此外,当您使用资源控制器时,您应该在 destroy 方法中接受模型。
使用 Route::list 检查你的控制器应该接受什么
You have a typo in the action element causing the form to be posted back to the same route as the original page;
note
action
is misspelledAlso, as you are using resource controller, you should accept the model in the destroy method.
Use Route::list to check what your controller should accept
表单中的操作NOT aciton Ex:
action NOT aciton in Your Form Ex :
我通过在web.php路由上覆盖销毁方法来找到解决方案。现在对我有用。
例如
并更改我的user_index.blade.php,
它可以正常工作。
I found the solution by overriding the destroy method with get on the web.php route. it's working for me for now.
such as
and change my user_index.blade.php
it works.