Skip to content

Instantly share code, notes, and snippets.

@filljoyner filljoyner/blade.php
Last active Oct 11, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.