Select an option and send ID

Asked

Viewed 34 times

0

Good morning friends. I have a question.. need that in a view I select an option that contains the name of the driver but need that in the controller I receive the ID of that driver and not the request with his name. Another option I thought is a field that visually shows the driver’s name but underneath is sending his ID. Below is my code:

    <div class="row">
        <div class="col-md-12">
            <div class="col-md-4">
                <div class="margin-bottom-10">
                    <label class="control-label">Motorista</label>                                    
                    <select class="bs-select form-control" name="nome_motorista" data-width="100px">
                    @foreach($motorista as $m)                      
                        <option value="motorista">{{$m->nome}}</option>
                    @endforeach                                                                        
                    </select>                    
                </div>
            </div>

Note that in the option the user will select a specific driver, but I need that in the controller I receive the ID of that driver. Can someone help me? If someone knows how to show an option only visually to the user and this option chosen send a data X to the bank, I thank you, also solve my question!!

1 answer

2


To send the driver code, just change the attribute value option and pass id instead of just "driver".

You can try something like this:

<select class="bs-select form-control" name="nome_motorista" data-width="100px">
    @foreach($motorista as $m)                      
        <option value="{{$m->id}}">{{$m->nome}}</option>
    @endforeach
</select>
  • Simple and effective, thanks Luciano, the judgment is already burning, not even thought about it. Hugs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.