0

i have a from to edit/ update data . on colomn input like name ,email ,date i dont have a problem because this value can e displayed at this colomn like this :

 <div class="item form-group">
                    <label class="control-label col-md-3 col-sm-3 col-xs-12" for="nama">NAMA <span class="required">*</span>
                    </label>
                    <div class="col-md-6 col-sm-6 col-xs-12">
                    <input id="nama" type="text" class="form-control @error('nama') is-invalid @enderror" name="nama" value="{{$pns->users->nama}}" required autocomplete="nama">

                        @error('nama')
                            <span class="invalid-feedback" role="alert">
                                <strong>{{ $message }}</strong>
                            </span>
                        @enderror
                    </div>
                  </div>

this value on this input is value="{{$pns->users->nama}}" and its still working , but how i can do this on this input ? this input is select dropdown list like this :

 <div class="form-group">
                      <label class="control-label col-md-3 col-sm-3 col-xs-12">Agama <span class="required">*</span></label>
                      <div class="col-md-6 col-sm-9 col-xs-12">
                        <select name="agama_id" id="agama_id" class="form-control">
                            @foreach($agama as $masters => $agamas )
                            <option value="{{ $masters }}">{{ $agamas }}</option>
                            @endforeach
                        </select>
                      </div>
                    </div>

where i can user this value like {{$pns->users->nama}} ??? if i open this update form , its will choose automaticlly like this db ??

someone have solution ?

3
  • Your collection is $masters? If so the foreach need to be like so: @foreach($masters as $agama) <option value="{{$agame->id}}">{{$agama->nama}}</option> Commented Nov 7, 2019 at 7:00
  • i dont know but its didnt work on my script , so i build like this Commented Nov 7, 2019 at 7:02
  • $agama = DB::table('master_agama')->pluck('agama','id'); Commented Nov 7, 2019 at 7:02

1 Answer 1

2

Try this.

<select name="agama_id" id="agama_id" class="form-control">
    @foreach($agama as $masters => $agamas )
         <option value="{{ $masters }}" @if ($pns->users->agama_id == $masters ) selected @endif>{{ $agamas }}</option>
    @endforeach
</select>
Sign up to request clarification or add additional context in comments.

1 Comment

you miss on users->nama , i changed with users->agama_id and its work sir . thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.