Support the ongoing development of Laravel.io →
posted 10 years ago
Requests
Last updated 2 years ago.
0

As current browsers do not implement DELETE verb Laravel simulates it via hidden fields. You have to do it with help of Form like this:

{{ Form::open(array('route' => array('accounts.destroy', $accountID), 'method' => 'delete')) }}
    <button type="submit" >Delete Account</button>
{{ Form::close() }}

More details explained here: http://stackoverflow.com/questions/19643483/crud-laravel-4-how-to-link-to-destroy

Last updated 2 years ago.
0

Thanks for the quick help! Worked like a charm :)

Last updated 2 years ago.
0

For those who don't want to use forms but javascript... Apparently, as i just found out, jQuery does the trick, too...

function checkDelete(id) {
if (confirm('Really delete?')) {
    $.ajax({
      type: "DELETE",
      url: '/<resource>/' + id,
      success: function(result) {
        // do something
      }
    });
  }
}
<a href="javascript:checkDelete(1);">...</a>

The advantage of this approach is that you can cancel it because of the confirmation box.

Cheers

Last updated 2 years ago.
0

You can also just the unobtrusive jquery adapter: https://github.com/rails/jquery-ujs That looks for data attributes, for methods (post/put/delete), confirm popups or send as ajax, without any additional javascript.

<a href="{{ route('accounts.destroy',array($accountID)) }}" data-method="delete" rel="nofollow" data-confirm="Are you sure you want to delete this?">Delete this entry</a>
Last updated 2 years ago.
0

@barryvdh

You can also just the unobtrusive jquery adapter: https://github.com/rails/jquery-ujs That looks for data attributes, for methods (post/put/delete), confirm popups or send as ajax, without any additional javascript.

I come across:

TokenMismatchException
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ShiFoo shifoo Joined 11 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.