Get data from an array with facade DB in laravel 5.5

1

Dear, I have the following query made with laravel

$datos = DB::table('mandato')
->join('compromiso_pago','mandato.CP_IdCompromisoPago','=','compromiso_pago.IdCompromisoPago')
->join('unidad_recaudadora','compromiso_pago.UR_IdUnidadRecaudadora','=','unidad_recaudadora.IdUnidadRecaudadora')
->join('tipo_recaudacion','compromiso_pago.TR_IdTipoRecaudacion','=','tipo_recaudacion.IdTipoRecaudacion')
->join('aporte','tipo_recaudacion.IdTipoRecaudacion','=','aporte.TR_IdTipoRecaudacion')
->where([
['unidad_recaudadora.Nombre','like','%'.$clave.'%'],
['unidad_recaudadora.D_IdDiocesis','=',10],
['compromiso_pago.TR_IdTipoRecaudacion','=',$idTipoRecaucadion->IdTipoRecaudacion]
])
->whereColumn('aporte.UR_IdUnidadRecaudadora','unidad_recaudadora.IdUnidadRecaudadora')
->groupBy('unidad_recaudadora.IdUnidadRecaudadora','unidad_recaudadora.CodMandatoAccess','compromiso_pago.TR_IdTipoRecaudacion','aporte.PorcentajeParroquial','tipo_recaudacion.Comision')
->select('unidad_recaudadora.IdUnidadRecaudadora','unidad_recaudadora.CodMandatoAccess','compromiso_pago.TR_IdTipoRecaudacion','aporte.PorcentajeParroquial','tipo_recaudacion.Comision')->first();

After the variable data I assign a value to another variable in this way:

$porcentajeParroquial = $datos->PorcentajeParroquial;
$comision = $datos->Comision;
$codigocorto = $datos->CodMandatoAccess;

but doing so gives me the following error

but for some reason when I use the function of laravel DD () if I get the result:

$porcentajeParroquial = $datos->PorcentajeParroquial;
dd($porcentajeParroquial);
$comision = $datos->Comision;
$codigocorto = $datos->CodMandatoAccess;

print me what would be the percentage value

Likewise I upload a print of the variables $ data

[Update]

I forgot to comment that I am doing a foreach and that a transaction is made to the database for each iteration

    
asked by Pablo Moraga 06.09.2018 в 00:07
source

2 answers

0

I'm on a cell phone so I can not see but according to what I understand you are not accessing an object but Array

Remember the basics of php, if your data collection is an object (object) you can enter its properties with

(->) "la flechita"

If your collection is an Array you can enter the properties with

([ ]) "Corchetes"

A simple way to see what kind of collection it is about if you do not know is to do

var_dum($variables);

die();


O 



print_r($variable);

exit();

Your line of code remains as follows.

$vaiable = $datos['dato espesifico'];
    
answered by 06.09.2018 в 00:48
0

After analyzing and investigating technical concepts online, the reason why the function did not reach the goal is because in a universe of 200 iterations, 8 of them came empty and at the time of associating, it fell apart when the reference was not found. (and it fell because it was not validating), the way I realized was the following

$a = [];
foreach ($NombresArray as $clave => $valor) {
    $datos = DB::table('mandato')
                                ->join('compromiso_pago','mandato.CP_IdCompromisoPago','=','compromiso_pago.IdCompromisoPago')
                                ->join('unidad_recaudadora','compromiso_pago.UR_IdUnidadRecaudadora','=','unidad_recaudadora.IdUnidadRecaudadora')
                                ->join('tipo_recaudacion','compromiso_pago.TR_IdTipoRecaudacion','=','tipo_recaudacion.IdTipoRecaudacion')
                                ->join('aporte','tipo_recaudacion.IdTipoRecaudacion','=','aporte.TR_IdTipoRecaudacion')
                                ->where([
                                    ['unidad_recaudadora.Nombre','like','%'.$clave.'%'],
                                    ['unidad_recaudadora.D_IdDiocesis','=',10],
                                    ['compromiso_pago.TR_IdTipoRecaudacion','=',$idTipoRecaucadion->IdTipoRecaudacion]
                                ])
                                ->whereColumn('aporte.UR_IdUnidadRecaudadora','unidad_recaudadora.IdUnidadRecaudadora')
                                ->groupBy('unidad_recaudadora.IdUnidadRecaudadora','unidad_recaudadora.CodMandatoAccess','compromiso_pago.TR_IdTipoRecaudacion','aporte.PorcentajeParroquial','tipo_recaudacion.Comision')
                                ->select('unidad_recaudadora.IdUnidadRecaudadora','unidad_recaudadora.CodMandatoAccess','compromiso_pago.TR_IdTipoRecaudacion','aporte.PorcentajeParroquial','tipo_recaudacion.Comision')->get();


                    $datos = $datos->toArray();
                    array_push($a,$datos);
                }
                dd($a);

Greetings, I hope it serves the future

    
answered by 06.09.2018 в 17:59