Skip to content

Instantly share code, notes, and snippets.

@cjaoude
Last active January 7, 2016 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cjaoude/817dfe6bcb5ade8fe38b to your computer and use it in GitHub Desktop.
Save cjaoude/817dfe6bcb5ade8fe38b to your computer and use it in GitHub Desktop.
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: http://laravel.com/docs/html#custom-macros
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