You can try to add '_method': 'delete' in data object and set type to post.
May 6, 2020
5
Level 1
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');
Level 10
Your route should be
Route::delete('/management/site/{id}','SiteController@destroy')->name('destroy')
Please or to participate in this conversation.