Quiero hacer la resta de dos resultados en una consulta sql, las consultas funcionan sin problema al intentar restarlos me muestra un error
$resultado= $data - $costo
y obtengo un error.
cada sql obtengo una coleccion y en ella solo tengo 1 valor
Object of class Illuminate\Support\Collection could not be converted to int
public function dadoGalatia($id)
{
$data = DB::table('invoices')
->join('invoice_details', 'invoices.id', '=', 'invoice_details.invoice_id')
->join('payment_methods', 'invoices.id', '=', 'payment_methods.invoice_id')
->select('payment_methods.amount')
->where('invoices.id', '=', $id)
->limit(1)
->get();
$costo=DB::table('invoices')
->join('invoice_details', 'invoices.id', '=', 'invoice_details.invoice_id')
->join('payment_methods', 'invoices.id', '=', 'payment_methods.invoice_id')
->select(DB::raw('sum(invoice_details.unit_cost * invoice_details.quantity) as total'))
->where('invoices.id', '=', $id)
->get();
$resultado= $data - $costo;
dd($resultado);
if ($data) {
return view('product/invoiceReport/PayBack',compact('data','costo'));
}
return response('', 404);
}