mercredi 1 août 2018

Select value id in multi-select drop-down Laravel and Jquery

I am working my way through a laravel form and did not realize until after the fact that my form needs a multiple select drop down. I have limited my code to what appears in the image. In my DB, the "tiers" populate as the id of 1, while the "specialties" populate as the name. I would like the specialty to populate as the id.

My view:

    <div class="container">
        

        <strong>Select Country:</strong>

        <select id="multiple-checkboxes2" multiple="multiple" name="specialties" value="specialties_id">
         @if($specialties)
             @foreach($specialties as $specialty)
                <option></option>
            @endforeach
        @endif
        </div>

    </select>
        

                <div class="form-group">
        {!! Form::label('tiers', 'Tiers:') !!}
        {!! Form::select('tiers',  $tiers, ['class'=>'form-control']) !!}
    </div>
        

  {!! Form::close() !!}

<script type="text/javascript">
$(document).ready(function() {
    $('#multiple-checkboxes2').multiselect();
});

Controller

public function store(Request $request)
{
    //
    Client::create([

        'specialties' => $request->specialties,
        'tiers'=>$request->tiers,



     ] );


         return redirect('/accounts');
}

The pic below demos how the tiers portion of the form is bringing back a one, while the specialties is bringing back a name.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire