简体   繁体   中英

How can I fetch Inserted value in dropdown in edit view in laravel?

I have code like this in my blade file

<div class="row">
    <label class="col-md-6"><b> Interview </b></label>
    <div class="col-md-6">
        <select class="custom-select form-control col-md-12" name="interview" id="interview" value="{{$candidateDetail->first_round['mode']}}" required>
            <option value=""> --- Select Interciew Round --- </option>
            <option value="technical">Technical Round</option>
            <option value="personal">Personal Round</option>
            <option value="hr">HR Interview</option>
            <option value="practical">Practical Round</option>
        </select>
    </div>
</div>
<hr>

Once I select value Hr from dropdown but now i want to change it from edit view than It only display simple dropdown It dont give me value that I last insert in database.

How can I solve that???

Try this

use Laravel collective for best practice

Your blade file

{{ Form::select('interview', $yourArray, $dbSaveValue, ['class'=> 'class name'])}}
//or
{{ Form::select('interview', $yourArray, $dbSaveValue ?? null, ['class'=> 'class name'])}}

$yourArray is your options

$dbSaveValue is your saved value it will automatically select option (No need to use for or foreach loop)

Suppose $check contains the actual data you inserted last time.. Change it with your variable.. Change code in your view

 <select class="custom-select form-control col-md-12" name="interview" id="interview" value="{{$candidateDetail->first_round['mode']}}" required>
        <option value=""> --- Select Interciew Round --- </option>
        <option value="technical" {{ $check=='technical' ? 'selected' : ''}}>Technical Round</option>
        <option value="personal" { $check=='personal' ? 'selected' : ''}}>Personal Round</option>
        <option value="hr" {{ $check=='hr' ? 'selected' : ''}}>HR Interview</option>
        <option value="practical" {{ $check=='practical' ? 'selected' : ''}}>Practical Round</option>
 </select>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM