我想生成一個顯示年份的下拉列表,到目前為止,這就是我所做的。我在下面的控制器中創建了一個方法。namespace App;use Illuminate\Database\Eloquent\Model;use Illuminate\Support\Carbon;use Illuminate\Support\Facades\Log;class RUMSModel extends Model{ protected $primaryKey = 'id'; protected $fillable = []; protected $dateFields = []; protected $dropdownFields = []; public $module_dir = ''; public $module = ''; public $importFields = []; public static $months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; public function selectYear($name, $startYear, $endYear, $selected = null, $options = array()) { $years = range($startYear, $endYear); $years = array_combine($years, $years); // [2013 => 2013] return $this->select($name, $years, $selected, $options); }?>使用它在 Blade 模板中顯示:<div class="col-lg-6"> <div class="form-group"> <label for="validation-latest_estimate_year"><b>Latest Estimate Year:</b></label> <select id="validation-latest_estimate_year" class="form-control" name="latest_estimate_year"> <option value="">-Select Year-</option> @foreach($model->selectYear('year') as $year) <option value="{{$year}}" {{$year == $model->latest_estimate_year ? 'selected': ''}}>{{$year}}</option> @endforeach </select> </div></div>但是,下拉列表不顯示年份。我試圖找出原因,但我沒有想法。專家的任何指導都會有所幫助。
2 回答

郎朗坤
TA貢獻1921條經驗 獲得超9個贊
為什么不selectYear()
從laravelcollective/html包中使用?
安裝:
composer require laravelcollective/html
視圖/刀片:
{!! Form::selectYear('year', 1900, 2019) !!}
- 2 回答
- 0 關注
- 182 瀏覽
添加回答
舉報
0/150
提交
取消