Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hik200's avatar

DELETE 405 (Method Not Allowed)

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}','SiteController@destroy')->name('destroy');
0 likes
5 replies
danieletulone's avatar

You can try to add '_method': 'delete' in data object and set type to post.

RamjithAp's avatar
Level 10

Your route should be

Route::delete('/management/site/{id}','SiteController@destroy')->name('destroy')
Snapey's avatar

Your route requires the id at the end, as confirmed by ziggy

uri: "management/site/{id}"

but your console message does not mention the id

console error DELETE http://localhost/blog/public/management/site

This might be caused by product_id being null

But anyway, as this was 4 days ago, you've probably sussed it by now.

hik200's avatar

resolved, with add in route

Route::delete('delete/{id}','SiteController@destroy')->name('destroy');

becouse route in 2 group mangament->site Full my routes

Route::group([ 'as'=>'management.','namespace' => 'Management', 'prefix' => 'management','middleware' => ['role:Super Admin'] ], function () {
	Route::get('/', 'ManagementController@index');
	Route::group(['as' => 'site.','prefix' => 'site'], function () {
		Route::get('/','SiteController@index')->name('index');
		Route::post('store','SiteController@store')->name('store');
		Route::post('edit/{id}','SiteController@edit')->name('edit');
		Route::get('edit/{id}','SiteController@edit')->name('edit');
		Route::patch('','SiteController@update')->name('update');
		Route::delete('delete/{id}','SiteController@destroy')->name('destroy');
		Route::get('{id}','SiteController@view')->name('view');
	});
});

RamjithAp's avatar

Based on the information you have provided in the question I have suggested this fix

Route::delete('/management/site/{id}','SiteController@destroy')->name('destroy');

However, you only know how many route groups above unless you show them to us. Anyway, you fixed it.

Please or to participate in this conversation.