Search the database and return the value - Laravel

0

I'm doing a search in my database, I want to get the value found and save it (are two different tables) but the value is not being saved, the number 0 is being saved.

I use this command in my controller:

$clientes = DB::table('cliente')->pluck('razaosocial', 'id');
return view('admin.contrato.create', ['cliente' => $clientes]);

And in my view I use this:

<div class="form-group col-md-5">
     {{ Form::label('cliente', 'Cliente') }}
         <select class="js-example-basic-multiple" name="cliente_id" >
            <option selected>Selecione o cliente</option>
              @foreach ($cliente as $cli)
                <option value="{{ $cli }}">{{ $cli }}</option>
              @endforeach
         </select>
</div>

When I use this the data appears to me, but I can not save it. I do not handle a lot of PHP, does anyone know how I can solve it?

    
asked by anonymous 17.05.2018 / 15:05

2 answers

0

Try:

@foreach ($cliente as $cli)
    <option value="{{ $cli->id }}">{{ $cli->razaosocial }}</option>
@endforeach
    
22.05.2018 / 14:55
0

You're moving to the database, Try this:

<div class="form-group col-md-5">
     {{ Form::label('cliente', 'Cliente') }}
         <select class="js-example-basic-multiple" name="cliente_id" >
            <option selected>Selecione o cliente</option>
              @foreach ($cliente as $key => $value)
                <option value="{{ $value }}">{{ $key }}</option>
              @endforeach
         </select>
</div>
    
18.05.2018 / 20:49