Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

brahim80's avatar

Laravel Selected Dropdown Value When Edit

Hello,

I encountered a problem to display a data to recover from the BD,

                    <label>Wilaya</label>
                    <select type="text" name = "avocat_wilaya" class="form-control" required id="avocat_wilaya" class="form-control">
                    
			            @foreach($group as $avocat)
        			    <option value="{{$avocat['wilaya_avocat']}}"  {{ $selectedvalue == $avocat['wilaya_avocat'] ? 'selected="selected"' : '' }}></option>
        				@endforeach

Thanks in advance,

0 likes
5 replies
redroseamit's avatar

try


 @foreach($group as $avocat)
  
  



<div class="form-group col-md-6">
                        <label > Wilaya </label>
                        <select  class="form-control" name = "avocat_wilaya" id="avocat_wilaya" >
                            <option selected>{{$avocat->example1}}</option>
                             <option selected>{{$avocat->examle2}}</option>
             
                        </select>
                    </div>
                </div>
   @endforeach 

brahim80's avatar

Hello,

Thank you for your reply,

and at the level of the controller code?

CorvS's avatar

What?

<select ...>                
    @foreach($group as $avocat)
        <option value="{{ $avocat['wilaya_avocat'] }}"  {{ $selectedvalue == $avocat['wilaya_avocat'] ? 'selected' : '' }}>...</option>
    @endforeach
brahim80's avatar

Hello,

Thank you for the answer,

But I have the version laravel 7.30

Please or to participate in this conversation.