how to make selected option using enum in laravel?

931 Views Asked by At

this is my code, how to make the selected option value in the edit form using enum data in the database? this is not working it just view the select option, not with id-data

this the code blade

 <!-- Modal  edit -->
     @foreach($daftar_pelanggan as $pelanggan)
     <div class="modal fade" id="editModal-{{ $pelanggan->id }}" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
       <div class="modal-dialog modal-dialog-centered" role="document">
          <div class="modal-content">
                <div class="modal-header">
                  <h5 class="modal-title mb-0" id="editModalLabel">Update Data Pelanggan</h5>
                </div>
              <div class="modal-body">
                 <!-- Card body -->
                <form role="form" action="{{ route('daftar_pelanggan.update') }}" method="POST" id="editForm">
                  @csrf
                  @method('PUT')
                    <!-- Input groups with icon -->
                  <div class="form-group row">
                      <label for="updateNamaPelanggan" class="col-md-2 col-form-label form-control-label">Nama</label>
                      <div class="col-md-10">
                      <input type="hidden" name="id"  value="{{ $pelanggan->id }}">
                        <input class="form-control" type="nama"  value="{{ $pelanggan->nama_pelanggan }}" id="updateNamaPelanggan" name="updateNamaPelanggan" required >
                      </div>
                    </div>
                    <div class="form-group row">
                      <label for="updateAlamat" class="col-md-2 col-form-label form-control-label">Alamat</label>
                      <div class="col-md-10">
                        <input class="form-control" type="alamat" value="{{ $pelanggan->alamat }}"  id="updateAlamat" name="updateAlamat" required>
                      </div>
                    </div>
                    <div class="form-group row">
                      <label for="updateNoTelp" class="col-md-2 col-form-label form-control-label">No.Telp</label>
                      <div class="col-md-10">
                        <input class="form-control" type="notelp" value="{{ $pelanggan->no_telp }}"  id="updateNoTelp" name="updateNoTelp" required>
                      </div>
                    </div>
                    <div class="form-group row">
                      <div class="col-md-6">
                        <div class="form-group">
                          <label class="form-control-label" for="updatePoin">POIN</label>
                          <input type="text" class="form-control" value="{{ $pelanggan->poin }}"  id="updatePoin"  name="updatePoin">
                        </div>
                      </div>
                      <div class="col-md-6">
                        <div class="form-group">
                          <label class="form-control-label" for="status_member">Kategori</label>
                            <select class="form-control" id="status_member" name="status_member" required="required">
                            <option value="" disabled selected>- Pilih -</option                              <option value="silver"{{($pelanggan->status_member === 'silver') ? 'selected' : '' }} >Silver</option>
                              <option value="gold" {{ ($pelanggan->status_member === 'gold'? 'selected' : '')}}>Gold</option>
                              <option value="diamond" {{($pelanggan->status_member === 'diamond')? 'selected' : ''}}>Diamond</option>
                            </select>    
                        </div>
                      </div>
                    </div>   
            </div>
            <div class="modal-footer">
              <button type="reset" class="btn btn-secondary" data-dismiss="modal">Reset</button>
              <button type="submit" class="btn btn-primary">Update Data</button>
            </div>
            </form>
         </div>
       </div>
    </div>
    @endforeach

this is select code this is not working what's wrong with this code?

 <option value="" disabled selected>- Pilih -</option                              <option value="silver"{{($pelanggan->status_member === 'silver') ? 'selected' : '' }} >Silver</option>
                              <option value="gold" {{ ($pelanggan->status_member === 'gold'? 'selected' : '')}}>Gold</option>
                              <option value="diamond" {{($pelanggan->status_member === 'diamond')? 'selected' : ''}}>Diamond</option>
                            </select>

and i edit with this still not working what's wrong with this code?

<select class="form-control" id="status_member-" name="status_member" required="required">
                                    @if($pelanggan->status_member == "silver")
                                        <option value="silver" selected="selected">Silver</option>
                                        <option value="gold">Gold</option>
                                        <option value="diamond">Diamond</option>
                                    @elseif($pelanggan->status_member == "gold")
                                        <option value="silver">Silver</option>
                                        <option value="gold" selected="selected">Gold</option>
                                        <option value="diamond">Diamond</option>
                                    @else
                                        <option value="silver">Silver</option>
                                        <option value="gold" >Gold</option>
                                        <option value="diamond" selected="selected">Diamond</option>
                                    @endif                              
                            </select> 
0

There are 0 best solutions below