【发布时间】:2018-11-30 20:58:30
【问题描述】:
我想在页面加载时将数据库中的选定值显示到下拉列表中。
我的控制器索引函数是:
public function index()
{
$country_data =DB::table('country')->select('country_id','country_name')->get();
$profile_data= DB::table('profiles')->select('*')->where('id',$user_id)->first();
return view('profile_update',compact('profile_data','country_data'));
}
数据库中高度的列名是:高度
我在 profile_update.blade.php 中的下拉菜单是
<select class="select4" name="country" id="country">
<option value="">Please Select</option>
@foreach($country_data as $country)
<option value="{{$country->country_id}}" {{$country_data->country == $country->country_id ? 'selected' : ''}}>{{$country->country_name}}</option>
@endforeach</select>
【问题讨论】:
-
类似于
<option value="5 Feet" @if($profile_data['Height'] == '5 Feet') selected @endif >5 Feet </option>的内容并重复其他选项。
标签: laravel select dropdown laravel-5.5 selectedvalue