hik200
5 months ago

DELETE 405 (Method Not Allowed)

Posted 5 months ago by hik200

Don't understand why have to error in the method. What I do wrong? I'm using Ziggy routing for js

management.site.destroy:
domain: null
methods: ["DELETE"]
uri: "management/site/{id}"

Have console error DELETE http://localhost/blog/public/management/site 405 (Method Not Allowed) have button and js on it

<button type="button" name="ok_button" id="ok_button" class="btn btn-danger">OK</button>

JS

$(document).on('click', '#ok_button', (function (e) {
    var product_id = $(this).val();
    var token = $("meta[name='csrf-token']").attr("content");
    $.ajax({
        url: route('management.site.destroy',product_id),
        beforeSend:function(){
            $('#ok_button').text('Deleting...');
        },
        type: 'delete',
        data: {'product_id':product_id,
            '_token': token,},
        success: function (data) {
                setTimeout(function(){
                    $('#confirmModal').modal('hide');
                    alert('Data Deleted');
                    location.reload();
                }, 2000);
        }
    });
}));

Controller:

    public function destroy($id)
    {

    	$company_id = Auth::user()->company_id;
	$item = Site::firstWhere(['company_id'=>$company_id,'id'=>$id]);
	$item->delete();
	return response()->json(['success' => 'Data is successfully Deleted']);
    }

Route

Route::delete('{id}','[email protected]')->name('destroy');

Please sign in or create an account to participate in this conversation.