Last active
June 27, 2018 02:16
-
-
Save getdave/0363a58e21de3cc44149 to your computer and use it in GitHub Desktop.
Laravel selectRange with default
This file contains hidden or 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