如何在编辑模式laravel中的下拉列表中选择默认值

In edit mode my selecte dropdown like this.

<select  name="comic_publisher" id="publishers" >
            @foreach($group as $team)
                <option value="{{$team['group_id']}}">{{$team['comic_group_name']}}</option>
            @endforeach
      </select>

and I want like if I edit the record the selected value associated with that record is by default here should be selected.

I am stuck with the little issue, can anyone please help me how to do that.

Thanks a lot.

You need to retrieve first database inserted value, and then check that value with all options if match found you can select like,

$db_selected_value = "2"; // retrieved data
<select name="comic_publisher" id="publishers" >
        @foreach($group as $team)
            <option value="{{$team['group_id']}}" @if($db_selected_value == $team['group_id']) {{ 'selected' }} @endif>{{$team['comic_group_name']}}</option>
        @endforeach
  </select>

here, @if($db_selected_value == $team['group_id']) {{ 'selected' }} @endif this line matches your old selected value to all the other. and selected selects

You can do it with adding selected key word to the option if it refers the old value, like this :

<select  name="comic_publisher" id="publishers" >
    @foreach($group as $team)
        <option value="{{$team['group_id']}}" {{ $oldGroupId == $team['group_id'] ? 'selected' : ''}}>{{$team['comic_group_name']}}</option>
    @endforeach
</select>

PS : you have to replece the $oldGroupId by the value of the edited element group id

<select  name="comic_publisher" id="publishers" >
        @foreach($group as $team)
            <option value="{{$team['group_id']}}" 
@if ($team['group_id'] == $someIdValueToBeSelectFromBacked ) {
'selected' }
 @endif>{{$team['comic_group_name']}}</option>
        @endforeach
  </select>