Im trying to save the value from a select that has the id's from tables in sql, but i dont know how to get the value from the select in my controller, i want to put my foreign key
= the value of the select , the type of the value in the select is integer
-Below i will let the code of my select and the code of my store function()
id_lugar
is the information that i showI tried this
$cliente_natural->fk_lugar=$('#municipio').val();
but doesnt work
Select code
<div class="form-group row">
<label for="lugar" class="col-md-5 col-form-label text-md-right">Estado</label>
<div class="col-md-6">
<select id="estado" name="id_lugar" class="form-control{{ $errors->has('id_lugar') ? ' is-invalid' : '' }}">
@foreach($lugares->get() as $index => $lugar)
<option value="{{ $index }}" {{ old('id_lugar') == $index ? 'selected' : '' }}>
{{ $lugar }}
</option>
@endforeach
</select>
@if ($errors->has('id_lugar'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('id_lugar') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group row">
<label for="lugar" class="col-md-5 col-form-label text-md-right">Municipio</label>
<div class="col-md-6">
<select id="municipio" data-old="{{ old('id_lugar') }}" name="id_lugar" class="form-control{{ $errors->has('id_lugar') ? ' is-invalid' : '' }}"></select>
@if ($errors->has('id_lugar'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('id_lugar') }}</strong>
</span>
@endif
</div>
</div>
Store function()
public function store(Request $request)
{
$cliente_natural=new Cliente_natural();
$cliente_natural->primer_nombre=$request->primer_nombre;
$cliente_natural->segundo_nombre=$request->segundo_nombre;
$cliente_natural->primer_apellido=$request->primer_apellido;
$cliente_natural->segundo_apellido=$request->segundo_apellido;
$cliente_natural->cedula=$request->cedula;
$cliente_natural->rif=$request->rif;
$cliente_natural->numero_carnet=$request->numero_carnet;
$this->validate(request(), [
'email' => 'required|email',
'password' => 'required|confirmed|min:8',
]);
//$cliente_natural->email=$request->email;
//$cliente_natural->password=$request->password;
$cliente_natural->fk_lugar=$('#municipio').val();
$cliente_natural->save();
return view('home.home2');
}