Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thaont-0210/1e4cf0dd27c1f04b04b50c3c76e9094d to your computer and use it in GitHub Desktop.
Save thaont-0210/1e4cf0dd27c1f04b04b50c3c76e9094d 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