我想把以前選擇的選項顯示為選中,我有兩個資料集。
我想對兩者進行比較,并想顯示被選中的國家,這些國家存在于用戶封鎖的colmn JSON編碼中
。 $user = User::find(auth()->user()->id);
$blocks = json_decode($user->blocked) 。
@foreach( Countries::orderBy('country_name')->get() as $country )
<選項value="{{$country->country_code}}" >{{ $country-> country_name }}</option>
@endforeach[/span]。
我嘗試了以下方法,但它選擇的是1值,要么是1st or last
@foreach ($sundaysArray as $key => $value)
@foreach( Countries::orderBy('country_name')->get() as $country )
<選項 @if( $value == $country-> country_code ) selected="selected" @endif value="{{$country-> country_code} >{{ $country-> country_name }}</option>
@endforeach[/span]。
@endforeach[/span].
uj5u.com熱心網友回復:
感謝@gert-b
$user = User::find(auth()->user()->id)。
$sundaysArray = json_decode($user->blocked) 。
@foreach( Countries::orderBy('country_name')->get() as $country )
<選項 @if (in_array($country-> country_code,$sundaysArray) selected="selected" @endif value="{{$country-> country_code} >{{ $country-> country_name }}</option>
@endforeach
uj5u.com熱心網友回復:
$selected = explode(",", $products-> suppliers_id) 。
<select name="supplier_id[]" multiple="multiple">
@foreach($suppliers as $supplier)
<選項值="{{ $supplier->id }}" {{ (in_array($supplier->id, $selected)) ? 'selected' : ' }}>{{ $supplier->name}}</option>
@endforeach
</select>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/307819.html
標籤:
