I do not believe that there is a way to achieve this using the built-in selectRange, however, using macro forms is possible. The following macro does roughly what you are looking for, but may require some cleaning.
Form::macro('selectRangeWithDefault', function($name, $start, $end, $selected = null, $default = null, $attributes = []) { if ($default === null) { return Form::selectRange($name, $start, $end, $selected, $attributes); } $items = []; if (!in_array($default, $items)) { $items['NULL'] = $default; } if($start > $end) { $interval = -1; $startValue = $end; $endValue = $start; } else { $interval = 1; $startValue = $start; $endValue = $end; } for ($i=$startValue; $i<$endValue; $i+=$interval) { $items[$i . ""] = $i; } $items[$endValue] = $endValue; return Form::select($name, $items, isset($selected) ? $selected : $default, $attributes); });
Usage is as follows:
{{ Form::selectRangeWithDefault('day', 1, 31, $day, 'Please Choose...') }}
Please note that I got the idea and foundation for my code: fooobar.com/questions/1200187 / ...
source share