简体   繁体   English

Laravel Axios删除失败

[英]Laravel axios delete fails

Am trying to perfrom a delete request on a resource route via\\ 我正在尝试通过\\在资源路由上执行删除请求

           this.$axios.delete("position-types", {data:this.deletedata})
                .then((res)=>{
                this.dialog = false;
                }, (err)=>{
                    this.dialog = false;
                })

In my routes i have 在我的路线上

Route::resource('/position-types', "PositionsTypesController");

In my PositionTypes controller i have 在我的PositionTypes控制器中,

    public function destroy(PositionsTypes $positionsTypes)
   {
    return $positionsTypes;
    //do stuff here
   }

When i try the above am getting an error 当我尝试以上时遇到错误

method 405 not allowed.

Where am i going wrong? 我要去哪里错了?

The problem is that when using resource controllers for delete you will have url like so: 问题是,使用资源控制器进行删除时,您将具有如下网址:

/position-types/{id}

so in axios you probably run it like this: 因此在axios中,您可能会这样运行:

 this.$axios.delete("position-types/2", {data:this.deletedata})
                .then((res)=>{
                this.dialog = false;
                }, (err)=>{
                    this.dialog = false;
                })

to delete resource with id 2 删除ID为2的资源

Remember - you can always run: 记住-您可以随时运行:

php artisan route:list

to verify what routes are defined in your application 验证您的应用程序中定义了哪些路由

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM