Skip to content

Instantly share code, notes, and snippets.

@samcrosoft
Created March 2, 2015 11:27
Show Gist options
  • Save samcrosoft/6efe2398e6627ee02841 to your computer and use it in GitHub Desktop.
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
/**
* 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