Allows requesting REST destroy()
action without sending FORM (by clicking on link)
- This is extension of https://www.github.com/WhipsterCZ/laravel-ajax library.
- Action
destroy()
will be called with AJAX - User have to confirm deletion. Custom message can be provided.
-
Copy source code to your public directory
-
Add script to your template
<script src="/js/laravel.ajax.js"></script>
<script src="/js/laravel.ajax.destroy.js"></script>
or use browserify
require('laravel-ajax');
require('laravel-ajax.destroy');
HTML
<a href="{{ route('model.destroy', $model) }}"
class="destroy"
data-confirm="Are you sure?"
>Delete</a>
Laravel action
public function destroy($id) {
Model::find($id)->delete();
return \Ajax::redirectBack();
}