我将如何使用 laravel5.2 select 数据
How will i able to select the data using laravel5.2
嗨,我是 laravel 的新手,我正在使用 5.2,我还在学习
我的问题是我如何才能 select 我在数据库中查询的数据?
下面是我的查看代码
<label>Target Country: </label>
<select name="country" id="country" class="form-control" onchange="getCityList(this.value, 'city')">
<option>Select Country :</option>
@foreach($countries as $country)
<option value="{{$country->id}} " ({{$countryId }} == {{$countryId}}) ? 'selected="selected"' : '' >{{$country->name}}</option>
@endforeach
</select>
还有我获取数据库数据的代码
$countryId = \App\Person::find($this->request->session()->get('newPersonId'))->companies()->get(['country_id'])[0]->country_id;
我希望结果是这样的:
<option value="{{$country->id}} " selected='selected; >{{$country->name}}</option>
非常感谢任何帮助! TIA
试试这个:
<option value="{{ $country->id }}" {{ $countryId == $country->id ? 'selected="selected"' : ''}}>{{ $country->name }}</option>
嗨,我是 laravel 的新手,我正在使用 5.2,我还在学习 我的问题是我如何才能 select 我在数据库中查询的数据?
下面是我的查看代码
<label>Target Country: </label>
<select name="country" id="country" class="form-control" onchange="getCityList(this.value, 'city')">
<option>Select Country :</option>
@foreach($countries as $country)
<option value="{{$country->id}} " ({{$countryId }} == {{$countryId}}) ? 'selected="selected"' : '' >{{$country->name}}</option>
@endforeach
</select>
还有我获取数据库数据的代码
$countryId = \App\Person::find($this->request->session()->get('newPersonId'))->companies()->get(['country_id'])[0]->country_id;
我希望结果是这样的:
<option value="{{$country->id}} " selected='selected; >{{$country->name}}</option>
非常感谢任何帮助! TIA
试试这个:
<option value="{{ $country->id }}" {{ $countryId == $country->id ? 'selected="selected"' : ''}}>{{ $country->name }}</option>