Show values in a Select combo in the view

0

my problem is that I can not show the value of the user's gender that already has a value assigned, this I want to show it in the select combo of the profile view, the select combo only shows me the default values but not the value already assigned to the user.

The Gender table has the values 1: Female, 2: Male, 3: Other

The user is assigned the value 2 (male), and the word "male" is what I want to show in the select menu as already selected when editing profile

This is the view

The default option of the select should be Male, which is what the user has assigned.

Thank you!

    
asked by Felipe 21.03.2018 в 21:26
source

1 answer

0

Look, something like this happens to your code, logic would be something like this.

<div class="form">
    <p>{{__('Genero')}}</p>
<select name="gender" id="gender" class="custom-select selector">
    @foreach($genders as $gender)
            @if(Auth:user()->id_genero == 'algo de valor aca')
        <option value="{{$gender->id}}" selected>{{$gender->name}}</option>
        @else
            <option value="{{$gender->id}}" selected>{{$gender->name}}</option>
        @endif
    @endforeach
</select>
</div>

With this I make that when the condition is fulfilled in the if this is selected.

    
answered by 21.03.2018 / 21:52
source