Search code examples
phplaravel-5

How to add default options


I just want to add default 'Please select' with selectMonth(), selectRange() and selectYear() function

my code

<div class="col-md-1"> {!! Form::selectRange('day', 1, 31) !!}</div>
<div class="col-md-1"> {!! Form::selectMonth('month') !!}</div>
<div class="col-md-1">{!! Form::selectYear('year', 1950, 2015) !!}</div>

Solution

  • No way. Just do by yourself.

    Form::select('day', ['' => 'Select day'] + array_combine(range(1, 31), range(1, 31)))
    Form::select('month', array_merge(['' => 'Select month'], range(1, 12)))
    Form::select('year', ['' => 'Select year'] + array_combine(range(1950, 2015), range(1950, 2015)))
    

    But I think that's ugly. Why don't you use any datepicker plugin?https://jqueryui.com/datepicker/

    Update:

    $months = array(); 
    foreach (range(1, 12) as $month) { 
        $months[$month] = strftime($format, mktime(0, 0, 0, $month, 1)); 
    }
    
    Form::select('month', array_merge(['' => 'Select month'], $months))