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
Related
I have multiple <select> by city filter
select in blade
<select id="city" multiple name="city[]">
#foreach($cities as $city)
<option value="{{ $city->id }}">{{ $city->name }}</option>
#endforeach
</select>
Query for select
if ($request->has('industry')) {
$businessesQuery->whereIn('industry_id', $request->input('industry'));
}
try this
#if(request('type') != "")
$('#city').find('option[value="' + "{{request('type')}}" + '"]').attr('selected', true);
#endif
little manage according to your code then its should work
I've been racking my head and can't seem to find something that will work to apply Laravel session value to selected value for drop-down menu. Here's the code I currently have. Greatly appreciate any help. Thanks.
<select class="form-control ml-2" style="width: 300px;" name="memberNameFilter" id="memberNameFilter">
<option value="-1">Member Name All</option>
#foreach($member_names as $names)
<option value="{{ $names->MemberName }}" #if($names->MemberName == request()->session()->get('memberNameFilter')) selected="selected" #endif>{{ $names->MemberName }}</option>
#endforeach
</select>
Use the sessionĀ helper function
For example, put something in the session
Route::get('/', function () {
session(['foo' => 'bar']);
return view('welcome');
});
And display it like so
<select name="" id="">
<option value="{{ session('foo') }}">{{ session('foo') }}</option>
<option value="baz">Baz</option>
</select>
Result
I'm working on validating my registration form.
If the input is a regular input, i can populate the previous value if it fails like so
<input type="tel" name="phone" value="{{old('phone')}}">
How do I populate the value on a select option?
<div class="input--select">
<label>Age Range <span>*</span></label>
<select name="age_range" class="age-range" value="{{old('age_range')}}" required>
<option selected disabled>Select your age range</option>
<option value="18-25">18-25</option>
<option value="26-35">26-35</option>
<option value="36-45">36-45</option>
<option value="46-55">46-55</option>
<option value="56-65">56-65</option>
<option value="66-75">66-75</option>
<option value="75+">75+</option>
</select>
#if ($errors->has('age_range')) <span class="error-message">Age range option is required.</span> #endif
</div>
I suggest putting all you ages in an array and pass that array to view:
$ages = ['18-25','25-50','50-75','75+']; // More dynamic and you can extend in anytime
Now changes in html :
<div class="input--select">
<label>Age Range <span>*</span></label>
<select name="age_range" class="age-range" value="{{old('age_range')}}" required>
// 1. first change which is creating your problem
<option {{ old('age_range') ? "" : "selected" }} disabled>Select your age range</option>
// 2. This is just optimization for short code
#foreach($ages as $age)
<option {{old('age_range') ==$age" ? $selected : ""}} value="{{$age}}">{{$age}}</option>
#endforeach
</select>
#if ($errors->has('age_range')) <span class="error-message">Age range option is required.</span> #endif
</div>
So in point 1 you are always applying the selected with first option.
Suppose your old value was 46-55
your html looks like :
<select name="age_range" class="age-range" value="{{old('age_range')}}" required>
<option selected disabled>Select your age range</option>
<option value="18-25">18-25</option>
<option value="26-35">26-35</option>
<option value="36-45">36-45</option>
<option selected value="46-55">46-55</option>
<option value="56-65">56-65</option>
<option value="66-75">66-75</option>
<option value="75+">75+</option>
</select>
if you take a look at above html there are 2 selected options. Html always picks the first one this is what creating the problem.
Point 1. will check if there is a old value available it will not apply the selected to the first placeholder option.
{!! Form::select('name', $varableyouwanttodisplay, old('name'),
['id'=>'id', 'class' => 'form-control select2', 'data-
placeholder' => 'select','required', 'style' => 'width:100%']) !!}
try like above code.
#php $selected = old('experience') ?: 66; #endphp
and than
{{ Form::select('experience', $experience, $selected, ['class' => 'form-control']) }}
This works in a case when a blade template loads for the first time and doesn't have 'old' value and you need predefined selected option(I.e. 66) for that case.
I had this problem while submitting form
blade
{{ Form::label('qualification', '') }}</th><td>{{ Form::select('qualification', $qualification, $jobs_list->qualification,array('class' => 'form-control')) }}
In this $qualification my full database list is there and $jobs_list->qualification is my selected value.but again am changing value and submitting form it stored as number because ex : value ="numbers"
controller:
$field = ToQualification::select('value')->get();
$qualification = array();
foreach($field as $user_qualification){
$qualification[] = $user_qualification->value;
}
generated html by blade code:
<select class="form-control" id="qualification" name="qualification">
<option value="0">Associate's</option>
<option value="1">Bachelor's</option>
<option value="2">Diploma</option>
<option value="3" selected="selected">Doctoral</option>
<option value="4">High Schools</option>
<option value="5">Master's</option>
</select>
anyone tell how to display name and id in table same as value in selection box?
I have a select box in my form that looks like below :
<select class="form-control" name="category_id" id="category_id">
#if(count($category_list)>0)
<option value="null">Pick a Category</option>
#foreach($category_list as $cl)
<option value="{{$cl->id}}">{{$cl->name}}</option>
#endforeach
#else
<option>No categories found</option>
#endif
</select>
My question is, how do I populate the select option with old selected option when the validation fails ? By populate I mean like {{old('input')}}..
I tried this way :
#if(old('category_id')
<option value="{{old('category_id')}}">{{old name ???}}</option>
#endif
But it will only get the category_id value, not the category name. How to get the old category name as well ? that's all and thanks!
you can do like this
#if(count($category_list)>0)
<option value="null">Pick a Category</option>
#foreach($category_list as $cl)
<option value="{{$cl->id}}" #if(old('category_id') == $cl->id) selected="selected" #endif>{{$cl->name}}</option>
#endforeach
#else
<option>No categories found</option>
#endif