【问题标题】:All Put & Delete route method Throw 302 error in my laravel vue js project我的 laravel vue js 项目中的所有 Put & Delete 路由方法抛出 302 错误
【发布时间】:2021-06-07 23:52:12
【问题描述】:

我正在开发一个 laravel vue js 应用程序。这里我有一个问题,所有 put & Delete 方法都抛出 302 错误
这是我的本地主机回复
这是我的服务器回复

一切都在我的本地电脑上完美运行,但是当我将它上传到服务器时,只有 get 和 post 方法才能完美运行。放置和删除方法抛出 302 错误。
我的路线

Route::apiResource('category','CategoryController');

我的控制器

 public function update(Request $request, Category $category)
    {
        $this->validate($request, [
            'name' => 'required',
        ]);

        $category->name = $request->name;
        $category->slug = Str::slug($request->name);
        $category->save();
    }

我的 Vue 组件(我正在使用 V-form)

updateData() {
                if (this.$middleware.admin()) {
                    this.$Progress.start();
                    this.form.put('api/category/' + this.form.id)
                        .then(() => {
                            Fire.$emit('getCategory');
                            $('#modal').modal('hide');
                            Toast.fire({
                                icon: 'success',
                                title: 'Category Updated successfully',
                            });
                            this.$Progress.finish();
                        })
                        .catch(() => {
                            this.$Progress.fail();
                        });
                }
            },

【问题讨论】:

标签: javascript php laravel vue.js


【解决方案1】:

尝试通过在表单中​​添加 <input type="hidden" name="_method" value="PUT"> 来欺骗您的方法。

或者您可以将_method: "PUT", 添加到组件的form 定义中。

查看文档:https://laravel.com/docs/8.x/routing#form-method-spoofing

【讨论】:

    猜你喜欢
    • 2021-11-30
    • 1970-01-01
    • 2016-02-25
    • 2019-03-27
    • 2021-06-01
    • 2017-10-24
    • 2014-08-21
    • 2022-11-10
    • 2018-02-13
    相关资源
    最近更新 更多