Last active
January 7, 2016 22:02
-
-
Save cjaoude/817dfe6bcb5ade8fe38b to your computer and use it in GitHub Desktop.
Laravel Form custom delete macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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