POST http://127.0.0.1:8000/api/configwarehouse/update/1 405(不允许使用方法)

我正在尝试将自己更新到数据库,但得到与上述相同的错误(我使用laravel 5.8,php 7.1):

POST http://127.0.0.1:8000/api/configwarehouse/update/1 405(不允许使用方法)

我的代码!

jQuery:

$.ajax({
    method: "GET",url: window.location.origin + "/api/trans",data: {},cache: false,dataType: "json",success: function(trans) {
        console.log(trans);
        trans.forEach(function(filter) {
            if (filter.StatusID==2) {
                var dataJSON = { 
                    "name": "test","ProductID": 1
                 };
                $.ajax({
                    method: "POST",url: window.location.origin + "/api/configwarehouse/update/" + filter.ProductID,contentType: "application/json; charset=utf-8",data: JSON.stringify(dataJSON),success: function(data) {
                        alert("OK");
                    }
                });
            }
        });
    },error: function(error) {
        console.log("err");
    },`enter code here`
});

控制器:

public function update(Request $request,$id)
{
    // dd($request);
    $product = ConfigWarehouse::findOrFail($id);
    $product->update($request->all());
    return $product;
}

API:

Route::group(['prefix'=>'configwarehouse'],function() {
      Route::get('/',[
       'as' => 'config.index','uses'   => 'Api\ConfigWarehouseController@index'
      ]);

    Route::get('/show/{id}',[
       'as' => 'config.show','uses'   => 'Api\ConfigWarehouseController@show'
    ]);

     Route::post('/store/{id}',[
      'as'  => 'config.store','uses'    => 'Api\ConfigWarehouseController@store'
     ]);

    Route::patch('/update/{id}',[
      'as'  => 'config.update',**strong text**
      'uses'    => 'Api\ConfigWarehouseController@update',]);
   });

https://diy.stackexchange.com

zhengxyx 回答:POST http://127.0.0.1:8000/api/configwarehouse/update/1 405(不允许使用方法)

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3162703.html

大家都在问