Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel中的下拉年份列表未显示_Php_Laravel - Fatal编程技术网

Php Laravel中的下拉年份列表未显示

Php Laravel中的下拉年份列表未显示,php,laravel,Php,Laravel,我想生成一个显示年份的下拉列表,到目前为止,这里是我所做的。我在下面的控制器中创建了一个方法 namespace应用程序; 使用Illumb\Database\Elount\Model; 使用照明\支持\碳; 使用Illumb\Support\Facades\Log; 类RUMSModel扩展了模型 { 受保护的$primaryKey='id'; 受保护的$fillable=[]; 受保护的$dateFields=[]; 受保护的$dropdownFields=[]; 公共$module_dir

我想生成一个显示年份的下拉列表,到目前为止,这里是我所做的。我在下面的控制器中创建了一个方法

namespace应用程序;
使用Illumb\Database\Elount\Model;
使用照明\支持\碳;
使用Illumb\Support\Facades\Log;
类RUMSModel扩展了模型
{
受保护的$primaryKey='id';
受保护的$fillable=[];
受保护的$dateFields=[];
受保护的$dropdownFields=[];
公共$module_dir='';
公共$module='';
公共$importFields=[];
公共静态$months=[“一月”、“二月”、“三月”、“四月”、“五月”、“六月”、“七月”、“八月”、“九月”、“十月”、“十一月”、“十二月];
公共函数selectYear($name、$startYear、$endYear、$selected=null、$options=array())
{
$years=范围($startYear,$endYear);
$years=array_combine($years,$years);//[2013=>2013]
返回$this->select($name,$years,$selected,$options);
}
?>
使用它在刀片模板中显示:

<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>

最新估计年度:
-选择年份-
@foreach($model->选择年份($year))作为$year)
最新估计年?选定年:''}}>{{{$year}
@endforeach

但是,下拉列表不显示年份。我想知道为什么,但是我没有主意了。专家的任何指导都会有所帮助。

为什么不使用软件包中的
selectYear()

安装:

composer require laravelcollective/html
视图/刀片:

{!! Form::selectYear('year', 1900, 2019) !!}

大家好,谢谢你们抽出时间来回答这个帖子。我找到了一个让它工作的方法,但我不知道这是否是最有效的方法

以下是我所做的工作:

<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="">{{$model->latest_estimate_year}}</option>
         @for ($year = date('Y') + 2; $year < date('Y') + 100; $year++)
            <option value="{{$year}}" {{$year == $model->latest_estimate_year ? 'selected': ''}}>{{$year}}</option>
         @endfor
       </select>
</div>

最新估计年度:
{{$model->最新估计值{u年}
@对于($year=date('Y')+2;$year{{$year}
@结束

向我们展示完整的代码,您的
$model
来自哪里?什么是
$this->选择
?您好,感谢您花时间回复。这是代码,我更新了我的帖子。你的控制器代码在哪里?