Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Laravel Form custom delete macro
// Create a 'delete' form in a single line. This Laravel form macro is a shortcut that
// creates a form with a DELETE method and a 'Delete' button. This macro saves you
// the trouble of creating a form each time you need to make a delete route.
// Place this code in a app/macros.php file and require this file in global.php
// ref:
Form::macro('delete', function($options){
$open = Form::open([
'route' => [ $options['route'], $options['id'] ],
'method' => 'DELETE',
$submit = Form::submit('delete');
$close = Form::close();
return $open . $submit . $close;
// usage (Blade example)
{{ Form::delete(['route' => 'users.destroy', 'id' => $user->id]) }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment