-
-
Save thaont-0210/1e4cf0dd27c1f04b04b50c3c76e9094d to your computer and use it in GitHub Desktop.
Laravel selectRange with default
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
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