1
Good afternoon, I have the following code in my locker:
<div class="form-group col-sm-6">
<label class="control-label">{{ trans('app.select_client')}} <span class="text-danger">*</span></label>
<select ng-model="cliente" class="form-control" name="cliente" id="cliente" required ng-init="cliente = '{{ old('cliente') }}'">
<option value="">{{ trans('app.select_client')}} </option>
@foreach($clientes as $data)
<option value="{{$data->id}}">{{$data->nomeCliente}}</option>
@endforeach
</select>
</div>
<div class="form-group col-sm-12">
<label class="control-label" >{{ trans('app.for')}}<span class="spancolor">*</span> </label>
<input type="text" class="form-control" value="" id="contato" ng-model="contato" name="contato" ng-init="contato='{{ old('contato') }}'" placeholder="{{ trans('app.contato')}}" required>
</div>
<div class="form-group col-sm-12">
<label class="control-label" >{{ trans('app.cc')}}<span class="spancolor">*</span> </label>
<input type="text" class="form-control" value="" id="cc" ng-model="cc" name="cc" ng-init="cc='{{ old('cc') }}'" placeholder="{{ trans('app.cc')}}" required>
</div>
I need to make the input id="contact" display the email of the selected client in select id="client"
My function in the controller
function getContatos(Request $request){
$value = $request->get('value');
$contatos = DB::table('clients')->select('contatos')->where('id', $value)->get();
$cc = DB::table('clients')->select('cc')->where('id', $value)->get();
echo $contatos;
echo $cc;
//return view('dashboard.dashboard_user',compact('contatos','cc'));
}
When I put the error Return What I need to return and show in the view is $contacts and $cc
$('select[name=cliente]').change(function () {
associaInput();
var value = $(this).val();
var _token = $('input[name="_token"]').val();
$.ajax({
url:"{{ route('cliente.getContatos') }}",
method:"POST",
data:{value:value, _token:_token},
success:function(result){
alert("success");
$("#contato").append($('#contato').val(value));
}
})
});
view function
Route::post('getContatos', 'DashboardController@getContatos')->name('cliente.getContatos');
Route
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Client extends Model
{
protected $table = 'clients';
protected $fillable = ['nomeCliente', 'contatos', 'cc', 'obscontatos', 'horarioInicial', 'horarioFinal', 'observacao', 'analistapreferencial', 'servicos'];
protected $casts = [
'cc' => 'array', 'obscontatos' => 'array', 'contatos' => 'array',
];
}
Model de Clients
In vdd I think you will have to use AJAX to get the client name and do this if with javascript.
– Vinicius De Jesus
Have you ever used auxiliary variable? always save the previous name in the course of cilclo ?
– Joy Peter
Good morning, could explain better the pq to have the second foreach running the same array. I couldn’t understand, maybe explaining better I can help you.
– Kayo Bruno
In the first input I go through the array to get {{$data->client name}} and in the second the value of {{$data->contacts}}
– Lorena
Only there in the second input I need to compare {{$data->client name}} with the value of the first input.
– Lorena
@Viniciusdejesus the client name I can already pick up and show in javascript, but I don’t know how I will access the $clients array in java script to scan.
– Lorena
@Lorena in my reply wanted you to post how comes the return of the request, in the console.log() I put
– Joan Marcos
@Joanmarcos jquery.js:10261 GET http://localhost/monitoring/public/getContacts? value=1&_token=wfzBV0Yzb2r2E6GPuTVeWJjLBhibMVPf7ozT7HS 500 (Internal Server Error)
– Lorena
@Lorena has a way to log the error message ? to see what really went wrong
– Joan Marcos
@Joanmarcos {,... } Exception: "Illuminate Database Queryexception" file: "C: xampp htdocs vendor monitoring Laravel framework src Illuminate Database Connection.php" line: 664 message: "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'contacts, cc' in 'field list' (SQL: select
contatos, cc
fromclients
Whereid
= 3)" trace: [{,... }, {,... }, {,... }, {,... },...]– Lorena
@Joanmarcos I don’t understand because, the connection with the bank and the columns are correct.
– Lorena
put your clients model :D
– Joan Marcos
@Joanmarcos Inseri na descrição da pergunta.
– Lorena
Let’s go continue this discussion in chat. @Lorena
– Joan Marcos