Created
March 2, 2015 11:27
-
-
Save samcrosoft/6efe2398e6627ee02841 to your computer and use it in GitHub Desktop.
This is a macro that will help you create a radio button that will compare a default value with the old request, this is a really helpful improvement over the radio method of 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
/** | |
* Create a radio button input field. | |
* | |
* @param string $name | |
* @param mixed $value | |
* @param bool $mDefault - this can be the default value for the radio | |
* @param bool $checked | |
* @param array $options | |
* @return string | |
* @static | |
*/ | |
Form::macro('detail_radio', function($name, $value = null, $mDefault =null, $bChecked = null, $options = []){ | |
if(null !== Input::old($name)) | |
{ | |
$bChecked = $value == Input::old($name) ? true : false; | |
}elseif(is_null($bChecked)){ | |
$mDefault = is_null($mDefault) ? "null" : $mDefault; | |
$bChecked = ($mDefault == $value) ? true: false; | |
} | |
$sTemp = Form::radio($name, $value,$bChecked, $options); | |
return $sTemp; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment