如何在Vue js和Laravel中更新数据?

时间:2020-04-20 15:02:54

标签: laravel vue.js

我正在尝试更新我的表格。由于某种原因,它可以在Postman中工作,但不能在浏览器中工作。我正在使用axios发出请求,并且在我所有的表单字段上都有v-model。 我已经尝试了PUT和PATCH,并且分别收到此错误:

The PATCH method is not supported for this route. Supported methods: GET, HEAD.

这是我的代码,用于在表单和Update函数中加载数据:

editProfile(profile) {
                this.editProfileData = {...profile};
                this.showEditProfileModal();
            },

updateProfile: async function() {

                axios.patch(this.uri + '/' + this.editProfileData.id, {

                    employment_type: this.editProfileData.employment_type,
                    date_of_birth: this.editProfileData.date_of_birth,
                    experience: this.editProfileData.experience,
                    skills: this.editProfileData.skills,

                }).then(response=>{

                    this.hideEditProfileModal();
                    this.$toast.success(response.data.message);

                })

                    .catch(error=>{
                        this.$toast.error(error.response.data.message);
                    });

            },

这是我的路线api.php:

Route::group(['middleware' => 'auth:api'], function() {

    Route::post('candidate/profile', function() {
        return response()->json([
            'message' => 'Candidate access',
            'status_code' => 200
        ], 200);
    })->middleware('scope:candidate');

    Route::post('candidate/profile/create', function() {
        return response()->json([
            'message' => 'Candidate access',
            'status_code' => 200
        ], 200);
    })->middleware('scope:candidate');

    // Route For Candidate Profile Pages
    Route::resource('/candidate/profile', 'CandidateProfileController', ['names'=>[

        'index'=>'candidate.profile.index',
        'create'=>'candidate.profile.create',
        'store'=>'candidate.profile.store',
        'edit'=>'candidate.profile.edit',
        'update'=>'candidate.profile.update'

    ]])->middleware('scope:candidate');


});

0 个答案:

没有答案