Last active
March 8, 2017 14:18
-
-
Save elena-kolevska/8315926 to your computer and use it in GitHub Desktop.
Laravel delete form macro.
http://blog.elenakolevska.com/restful-deleting-in-laravel/
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
/* | |
|-------------------------------------------------------------------------- | |
| Delete form macro | |
|-------------------------------------------------------------------------- | |
| | |
| This macro creates a form with only a submit button. | |
| We'll use it to generate forms that will post to a certain url with the DELETE method, | |
| following REST principles. | |
| | |
*/ | |
Form::macro('delete',function($url, $button_label='Delete',$form_parameters = array(),$button_options=array()){ | |
if(empty($form_parameters)){ | |
$form_parameters = array( | |
'method'=>'DELETE', | |
'class' =>'delete-form', | |
'url' =>$url | |
); | |
}else{ | |
$form_parameters['url'] = $url; | |
$form_parameters['method'] = 'DELETE'; | |
}; | |
return Form::open($form_parameters) | |
. Form::submit($button_label, $button_options) | |
. Form::close(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment