I want to update two values in my data I want to update the first value as an int and the other one is string.
TABLE STRUCTURE
here is my input, the value aircraft_id
is the first one to update and the other one is the aircraft_refistration_number
<select name="aircraft_id" class="form-control" id="">
<option value="0" disabled="true" selected="true"> Select </option>
@foreach ($aircrafts as $aircraft)
<option value="{{ $aircraft->aircraft_id }}">{{ $aircraft->aircraft_registration_number }}</option>
@endforeach
</select>
here is my table
here is where i update the registered_company_name
which has to be string but then the output is the aircraft_id
$txtDescript = $request->input('aircraft_id');
$aircraft = DB::table('settings')
->where('id', 4)
->update(['description' => $txtDescript]);
here is the aircraft_id
which should be int or id's
$airid = $request->input('aircraft_id');
$aircraft = DB::table('series')
->update(['aircraft_id' => $airid]);
this one perfectly works
here is my output of the problem
WHEREAS it should be like THIS output which should be correct
you can take this longer form,
<select name="aircraft_id" class="form-control" id="">
<option value="0" disabled="true" selected="true" id="airselect"> Select </option>
@foreach ($aircrafts as $aircraft)
<option value="{{ $aircraft->aircraft_id }}">{{ $aircraft->aircraft_registration_number }}</option>
@endforeach
</select>
<input type="hidden" name="aircraft_name" id="aircraft_name" value="">
and set the value of the hidden field using jquery like so
$(document).ready(function(){
$(document).on('change','.airselect',function(){
$selected=$( "#airselect option:selected" ).text();
$('#aircraft_name').val($selected);
});
});
and then adjust your controller like so
$txtDescript = $request->input('aircraft_name');
$aircraft = DB::table('settings')
->where('id', 4)
->update(['
description' => $txtDescript]);
and
$airid = $request->input('aircraft_id');
$aircraft = DB::table('series')
->update(['aircraft_id' => $airid]);
try it and let me here from you, i did not test the code
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.