a dynamic selection

0

the BD "deposits"

'id', 'cantidad', 'num_autorizacion', 'fecha', 'asesor', 'created_at', 'updated_at', 'encontrado', 'contrato_id'

in the controller

$depositos = Deposito::orderBy('fecha')
        ->whereIn('encontrado', ['no'])
        ->lists('num_autorizacion','id');

return view('payments.paid', ['depositos' => $depositos]);

in the payments.paid view

{!! Form::select('autorizacion', $depositos, null, ['class' => 'form-control']) !!}

in the view I see the list of all the "num_authorization" and when I select one, it is already linked to the id and I can do operations. in that part all good. but there is a way that the select list shows me "num_authorization" + "quantity".

example I have in the BD

1:$500:0001
2:$400:0002
3:$650:0003

currently shows me

"0001"
"0002"
"0003"

but I would like the list to come out

"0001 - $500"
"0002 - $400"
"0003 - $650"

Can you understand me? greetings .-

    
asked by Luis Cárdenas 05.11.2016 в 19:12
source

1 answer

1

Try changing in your controller:  the query like this:

$depositos = Deposito::select('id', DB::raw('CONCAT(num_autorizado, " - ", cantidad) AS num_cant') )
    ->orderBy('fecha')
    ->whereIn('encontrado', ['no'])
    ->lists('num_cant','id');

and the view like this:

{!! Form::select('num_cant', $depositos, null, ['class' => 'form-control']) !!}
    
answered by 05.11.2016 / 20:15
source