I have 2 variables in my controller but only one pulls me

1
$ingreso=DB::table('INGRESO as i')
            ->join('PERSONA as p','i.ID_PER','=','p.ID_PER')
            ->join('DETALLE_INGRESO as di','i.ID_ING','=','di.ID_ING')
            ->select('i.ID_ING','i.FECHA_HORA','p.nombre','i.TIP_COMP','i.SERIE_COMP','i.NUM_COMP','i.impuesto','i.estado',DB::raw('sum(di.cantidad*PRECIO_COMPRA)as total'))
            ->where('i.ID_ING','=',$id)
            ->first();

        $detalles=DB::table('DETALLE_INGRESO as d')
        ->join('Articulo as a','d.ID_ARTI','=','a.ID_ARTI')
        ->select('a.nombre as Articulo','d.cantidad','d.PRECIO_COMPRA','d.PRECIO_VENTA')
        ->where('d.ID_ING','=',$id)
        ->get();

        return view("compras.ingreso.show",["ingreso"=>$ingreso,"detalles"=>$detalles]); 

My problem is that it only reads the variable "income".

{{Form::Open(array('action'=>array('IngresoController@show',$ing->ID_ING,$detalle->ID_ING)))}}
    
asked by gt_150699 24.08.2018 в 19:17
source

1 answer

1

You are accessing $detalles as if it were only an object when it is really a set of records, if you just wait for a record use:

$detalles=DB::table('DETALLE_INGRESO as d')
    ->join('Articulo as a','d.ID_ARTI','=','a.ID_ARTI')
    ->select('a.nombre as Articulo','d.cantidad','d.PRECIO_COMPRA','d.PRECIO_VENTA')
    ->where('d.ID_ING','=',$id)
    ->first();

If you are going to print all you can do a foreach on blade, it would be something like:

@foreach($detalles as $det)
{{--código para mostrar la información--}}
@endforeach

On the other hand I think you are using the same attribute in the parameters $ing->ID_ING,$detalle->ID_ING , why not handle something like:

{{Form::Open(array('action'=>array('IngresoController@show',$ing->ID_ING,$ing->ID_ING)))}}

or

{{Form::Open(array('action'=>array('IngresoController@show',$ing->ID_ING,$detalle->first()->ID_ING)))}}
    
answered by 24.08.2018 в 19:44