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

时间:2019-11-05 02:17:02

标签: javascript php jquery

我正在尝试将自己更新到数据库,但得到与上述相同的错误(我使用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),
                    dataType: "json",
                    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

0 个答案:

没有答案