此路由不支持 DELETE 方法。支持的方法:GET、HEAD、POST

发布于 2025-01-20 04:09:41 字数 1108 浏览 0 评论 0原文

我正在使用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.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

余生共白头 2025-01-27 04:09:41

您的操作元素中存在拼写错误,导致表单被发布回与原始页面相同的路由;

<form method="POST" aciton="{{ route('kullanicilar.destroy',$user->id) }}"

注意 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;

<form method="POST" aciton="{{ route('kullanicilar.destroy',$user->id) }}"

note action is misspelled

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

世界和平 2025-01-27 04:09:41

表单中的操作NOT aciton Ex:

<form method="POST" action="{{ 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>

action NOT aciton in Your Form Ex :

<form method="POST" action="{{ 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>
当爱已成负担 2025-01-27 04:09:41

我通过在web.php路由上覆盖销毁方法来找到解决方案。现在对我有用。

例如

 //this should be at the top
Route::get('kullanicilar/remove/{id}', [UserController::class,'destroy'])->name('kullanicilar.remove'); 
Route::resource('kullanicilar', UserController::class); 

并更改我的user_index.blade.php,

<a href="{{ route('kullanicilar.remove',$user->id) }}"  title="Sil" class="btn btn-sm btn-danger"><i class="fa fa-times"></i></a>

它可以正常工作。

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

 //this should be at the top
Route::get('kullanicilar/remove/{id}', [UserController::class,'destroy'])->name('kullanicilar.remove'); 
Route::resource('kullanicilar', UserController::class); 

and change my user_index.blade.php

<a href="{{ route('kullanicilar.remove',$user->id) }}"  title="Sil" class="btn btn-sm btn-danger"><i class="fa fa-times"></i></a>

it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文