jeudi 5 septembre 2019

Laravel get multi selected drop down value to controller

I have a form with multi-select dropdown

<form role="form" method="post" action="" autocomplete="off">
        <div class="col-12">
            @csrf
            <div class="form-group ">
                <select class="selectpicker " name="defect-type-id" id="defect-type-id" multiple data-style="selectpicker-style" data-width="100%" title="Defect Types">
                    @foreach(App\DefectType::select('id','title')->get() as $defect_type)
                        <option value=""></option>
                    @endforeach
                </select>
                @if ($errors->has('defect-type-id'))
                <span class="invalid-feedback" role="alert">
                    <strong></strong>
                </span>
                @endif
            </div>
        </div>
        <div class="col-12">
        <div class="text-center">
            <button onclick="return confirm('Are you sure to associate this contractor?')" type="submit" class="btn btn-primary my-4">Associate</button>
        </div>
    </div>
</form>

when I want to get the value in controller I only receive 1 selected value instead of a list of selected option :

public function postAddDeveloperContractorAssociation(Request $request ) {

    $defect_type_id = $request->input('defect-type-id');
    dd($defect_type_id);
    return redirect()->route('dev-admin.developer-contractor-associations.index')->withStatus(__('Contractor has been added.'));

}

When I dd this all i get is something like "2" instead of [1, 2, 3] or something like that



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire