Skip to content

Instantly share code, notes, and snippets.

@filljoyner
Last active October 11, 2018 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filljoyner/dde6aa886bf49b17b8e9c74cb988f583 to your computer and use it in GitHub Desktop.
Save filljoyner/dde6aa886bf49b17b8e9c74cb988f583 to your computer and use it in GitHub Desktop.
Laravel Delete Link with jQuery
<a href="#" data-delete="{{ route('account.bots.pages.destroy', ['bot_id' => $bot->id, 'id' => $page->id]) }}" class="text-danger">
Delete
</a>
$(document).ready(function($) {
$('a[data-delete]').on('click', function(evt) {
evt.preventDefault();
var form_id='delete_'+Math.floor((Math.random() *1000) +1);
if(confirm('Are you sure?')) {
$(this).after(function() {
form='<form id="'+form_id+'" action="'+$(this).data('delete') +'" method="post">';
form+='<input type="hidden" name="_token" value="'+$('meta[name="csrf-token"]').attr('content') +'">';
form+='<input type="hidden" name="_method" value="DELETE">';
form+='</form>'
return form;
});
$('#'+form_id).submit();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment