lundi 27 mars 2017

Laravel 5.4 - MethodNotAllowedHttpException in RouteCollection.php line 233

In my laravel 5.4 app, i have a crud module. for the edit bit, the data is rendered in a bootstrap modal. the data is pulled successfully but on hitting the update button, the error shown is returned.

here's my blade form that's rendered in the modal:

<form id="formEdit" class="form-horizontal" role="form" method="put">
//form elements
</form>

here's the ajax that handles it:

//edit_id is defined globally
$('#updateClass').click(function(){
        var name = $("#formEdit #name").val();
        var status = ($('#formEdit #status').prop("checked") == true) ? 1 : 0;
        var token = $('meta[name="csrf-token"]').attr('content');
        var id = edit_id;
        var url = "classes/update/"+id;
        var formdata = {
            'name' : name,
            'status' : status,
            '_token' : token
        };

        $.ajax({
            method: "PUT",
            url: url,
            data: formdata,
            dataType: "json"
        })
        .done(function(data) {
            //
        })
        .fail(function(data) {
            //

            });
        });
    });

updateClass is the button that displays the edit form on the modal..

here's my routes in web.php:

Route::resource('classes', 'ClassesController');

Route::group(['prefix' => 'admin'], function () {
    Route::get('classes', 'ClassesController@index');

    Route::get('classes/edit/{id}',  'ClassesController@edit');
    Route::put('classes/update/{id}',  'ClassesController@update');
});

and finally, my update function in the classes controller:

public function update(Request $request, $id)
    {
        $validator = $this->validator($request->all());
        $errors = $validator->errors();
        $errors = json_decode($errors);

        if ($validator->passes()) 
        {
            Dl_class::find($id)->update($request->all());
            return response()->json();
        }
        else
        {
            return response()->json($errors, 422);
        }
    }

what i'm i missing?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2nnCfmX
via IFTTT

Aucun commentaire:

Enregistrer un commentaire