I want to add other value as one of the options and show a new input field to write new value doesn't exist in options.
This is the value of my options ON my Seed part.
public function run()
{
Model::unguard();
//delete table records
DB::table('providers')->delete();
//insert some dummy records
DB::table('providers')->insert(array(
array('id'=>'1','name'=>' private'),
array('id'=>'2','name'=>' public'),
array('id'=>'3','name'=>' semi private'),
array('id'=>'4','name'=>'other'),
));
}
and this is my code in the form
<div class="form-group">
<label for="provider_id"> Provider Type </label><br>
<select name="provider_id" class="form-control" style="width:50%" required>
<option></option>
@foreach($providers as $provider)
<option value="{{$provider->id}}">{{$provider->name}}</option>
@endforeach
</select>
<input name="provider" style="width:50%" id="provider_id4" hidden="hidden" />
</div>
And this is javascript code
$("#provider_id").change(function () {
var selected_option = $('#provider_id').val();
if (selected_option === '4') {
$('#provider_id4').attr('pk','1').show();
}
if (selected_option != '4') {
$("#provider_id4").removeAttr('pk').hide();
}
})
I want to store old value(1,2,3) and new if the user chose 4 in provider_id column in database which I store this column in my controller
$excuse->provider_id = $request->input('provider_id');