RouteCollection.php第207行中的MethodNotAllowedHttpException

时间:2019-01-17 19:20:44

标签: php ajax laravel

我是laravel的新手,但有一个问题,但无法解决。我已经在这里看到了官方文档以及其他一些问题,但我无法解决。

我想要实现的是对数据库的更新,但是由于不成功,我只是试图发送一条响应,并带有一些我也无法使其正常工作的消息。 我正在尝试通过ajax进行操作,我想将信息发送到控制器,然后执行更新,在这种情况下,它会响应一条简单消息...

这是我的路线:

Route::patch('pdv/inventario-transferencia/{store}/{idTran}/update', 'InventoryController@editQtTemp');

这是我通过按下按钮执行的代码:

$('.btn-qtyTemp').click(function(e) {
    //ADAN
    e.preventDefault();
    id_el = $(this).data('id');
    valInput = document.getElementById('input-'+id_el).value;      
    el = id_el.replace("quantityTemp-", "");
    var  valueIdTran = parseInt(el);
    if(!isNaN(valueIdTran)) {

         $.ajaxSetup({
            headers: {
                'X-XSRF-Token': $('meta[name="_token"]').attr('content')
            }
        });

        $.ajax({
            type: 'patch',
            url: location.pathname + '/' + el + '/update',
            dataType: 'json',
            data: {
                isValInput: valInput
            },
            beforeSend: function () {
                console.log('entrando');
            },
            success: function (data) {
                console.log('Todo Correcto'+data.isId);
            },
            error: function (data) {
                console.log('Algo anda mal'+data.isId);
            }
        });
    }
    //      alert('id_el: '+id_el+' el: '+el+' value: '+valueIdTran+' val: '+valInput);
});  

这是控制器的功能:

public function editQtTemp(Request $request, $store, $idTran) {


       if ($request->ajax()) {

            $this->validate($request, [
                'isValInput' => 'required'
            ]);

            //
            $isValInput = $request->input('isValInput');

            if ($isValInput=='') {
                # code...
                return response()->json([
                    'isId' => ['Valor Invalido']
                ], 422);
            }
            else {
                return response()->json([
                    'isId' => [$isValInput]
                ], 200);
            }
        }
}

出现在我下面的错误是

MethodNotAllowedHttpException in RouteCollection.php line 207:


    in RouteCollection.php line 207
    at RouteCollection->methodNotAllowed(array('POST')) in RouteCollection.php line 194
    at RouteCollection->getRouteForMethods(object(Request), array('POST')) in RouteCollection.php line 142
    at RouteCollection->match(object(Request)) in Router.php line 729
    at Router->findRoute(object(Request)) in Router.php line 652
    at Router->dispatchToRoute(object(Request)) in Router.php line 628
    at Router->dispatch(object(Request)) in Kernel.php line 214
    at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 43
    at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 36
    at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
    at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
    at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
    at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
    at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
    at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 100
    at Pipeline->then(object(Closure)) in Kernel.php line 115
    at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
    at Kernel->handle(object(Request)) in index.php line 52

我不知道会发生什么,我已经在纯PHP中完成了此任务,但是使用laravel却遇到了很多问题...谢谢

0 个答案:

没有答案