Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bhhussain's avatar

Passing two values from the dropdown to the controller

Would like to save the addon_price and addon_name in the table called booking.

addon_price and addon_name coming from the table called addon.

I have solve this by passing the id from the addon to the value and in controller I have use the below to save in table but I need the price in the view side to calculate the amount.


                                        <select class="custom-select" name="tb_addon1_price" id="tb_addon1_price"
                                        onchange="calc4()">
                                          <option value="" selected disabled hidden>Please select</option>
                                          @foreach($addon as $c)
                                          <option value="{{ $c->addon_price}}">{{ $c->addon_name}}</option>
                                          @endforeach   
                                          
                                          </select>

$record = Addon::find(request('id'));
        $booking->tb_addon1_name = $record->addon_name;  
0 likes
3 replies
ollie_123's avatar

I was trying to do the same the other day and it was recommended that I use a pivot table to do this. I would suggest you look into it also.

fylzero's avatar
fylzero
Best Answer
Level 67

@bhhussain Your question is a bit unclear. Your form is passing price. Your controller is trying to get the id.

If you want to pass two values in a dropdown I would do this with a hidden field and javascript.

<input type="hidden" id="nameVal" name="nameVal">

<select id="priceVal" name="priceVal">
    <option value="price1">Name1</option>
    <option value="price2">Name2</option>
</select>

Then...

$('#priceVal').on('change', function() {
    var selectedName = $('#priceVal option:selected').text();
    $('#nameVal').val(selectedName);
}

Please or to participate in this conversation.