Skip to content

Instantly share code, notes, and snippets.

@getdave
Last active June 27, 2018 02:16
Show Gist options
  • Save getdave/0363a58e21de3cc44149 to your computer and use it in GitHub Desktop.
Save getdave/0363a58e21de3cc44149 to your computer and use it in GitHub Desktop.
Laravel selectRange with default
Form::macro('selectRangeWithDefault', function($name, $start, $end, $selected = null, $default = null, $attributes = [])
{
if ( is_null($default) ) {
return Form::selectRange($name, $start, $end, $selected, $attributes);
}
$range = array_combine($range = range($start, $end), $range);
$range = [null => $default] + $range;
return Form::select($name, $range, $selected, $attributes);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment