Laravel 7. PHP 7.4。 我的网站格式很长。我有2个下拉菜单。这两个下拉列表都应该显示说“ 1920年-2020年”
的年份列表我的第一个下拉列表是使用ajax从数据库填充年份列表。现在,逻辑开始起作用了。我需要第二个下拉菜单显示的年份列表应大于为第一个下拉列表选择的年份。
例如,在第一个下拉菜单中,如果用户选择年份 1950 ,则第二个下拉菜单应从 1951-2020 开始。
我想知道如何在Laravel中做到这一点?
刀片
<div class="form-group">
<select id="first_dropdown" data-dependent="second-dropdown">
<option value="">1920</option>
<option value="">1921</option>
<option value="">1922</option>
...................
</select>
</div>
<div class="form-group">
<select id="second_dropdown" >
<option selected value=""></option>
</select>
控制器
public function fetchYear(Request $request)
{
$get_model_id = $request->get('model_id');
$model_dependent = $request->get('model_dependent');
$fetch_year = DB::table('my-database')
->select('year')
->distinct()
->where('model_id', '=', $get_model_id)
->where(function ($query) {
$query->orWhere('is_active', '=', '1');
})
->orderBy('year', 'ASC')
->get();
$show_year = '<option value="">Select ' . ucfirst($model_dependent) . '</option>';
foreach ($fetch_year as $row) {
$show_year .= '<option value="' . $row->year . '">' . $row->year . '</option>';
}
echo $show_year;
}