Post method is not supported for route in vuejs and laravel

Viewed 411

I want to update status on confirm click to 1. i am using vue js and laravel. i used axios.post for hit the API. but when i click on confirm to update status, i get error message for route post is not supported.

please help me to find my mistake.

unconfirmedareas.vue

  

    ConfirmArea(index){
                        var confirmArea = confirm("Are you sure you want to confirm this area?");
                        if(confirmArea){
                            axios.post('/admin/areaConfirmed/'+index,{
                                status:1,
                           }).catch(({response}) => {
                            this.$toast.error(response.data.message, 'Error', {timeout: 3000});
                        }).then(({data}) => {
                            this.$toast.success(data.message, 'Success', {timeout: 3000});
                            this.fetchUnconfirmedSellers();
                        });
                    }
                    },

web.php


Route::post('areaConfirmed','SellerController@confirmArea')->name('areaConfirmed');

sellercontroller.php

 

    public function confirmArea(Request $request, $id)
        {
            $confirmArea = Areas::find($id);
            $confirmArea->status = $request->status;
            $confirmArea->save;
    
            return response()->json([
                'message' => 'Area has been confirmed'
            ]);
        }

2 Answers

1- You have to add the id to your route like this :

Route::post('areaConfirmed/{id}','SellerController@confirmArea')->name('areaConfirmed');

Cause the route without the id param it's a different route.

2 - Also this is the correct way to get a POST input $request->post('param_name') :

$confirmArea->status = $request->post('status');

as FAROUK BLALOU said, and by any chance if u didn't add the 'admin' part in the prefix in config then Route::post('admin/areaConfirmed/{id}','SellerController@confirmArea')->name('areaConfirmed'); should be like this.

Related