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.
Feb 10, 2020
3
Level 2
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;
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.