Cumulate in column - could not be converted to int

0

I have the following code in a controller:

$total = DB::table('pedidos')->where('idUSUARIOS', $usuario)
                              ->orWhere('ESTADO','P')
                              ->pluck('TOTAL');

$precio=$request->get('precio');

DB::table('pedidos')
        ->where('idPEDIDOS',$idpedido)
        ->update(['TOTAL' => $total+$precio]);

What you are trying to do is what is in the TOTAL column to accumulate the price of another product, but I get an error in the following line:

->update(['TOTAL' => $total+$precio]);

The error it gives is:

Object of class Illuminate\Support\Collection could not be converted to int

Does anyone know the reason for this error?

Thank you very much in advance.

    
asked by Didac 12.07.2018 в 13:05
source

1 answer

1

In the end I solved it as indicated by Alfredo, but I also had to add the following code before the update:

$precio=floatval(str_replace(",","",$precio));
$total=floatval(str_replace(",","",$total));
$total=$total+$precio;

In case someone has the same problem. I have transformed the fields from decimals to float.

    
answered by 12.07.2018 в 14:04