Get list of products with VAT included

2

I have a product model with the column price and VAT How can I get the final price (with percentage of VAT included) Especially when I do something like

\App\Producto::where('marca_id', 4)->paginate();

Thanks

    
asked by Diego G 06.12.2018 в 01:54
source

1 answer

0

It occurs to me that you build the query in this way:

$datos = Producto::selectRaw('precio * IVA AS PrecioFinal')
                  ->where('marca_id', 4)
                  ->get();

The new column is called FinalPrice and is calculated by multiplying the precio by the IVA within the method selectRaw()

The above is only going to return the calculated field; but if you need all columns plus the new calculated column; you should do the following

$datos = Producto::selectRaw('*, precio * IVA AS PrecioFinal')
                  ->where('marca_id', 4)
                  ->get();

That is, within the selectRaw() method we pass a *, that helps us indicate that it brings all the columns and the one that will be calculated on the flight

    
answered by 06.12.2018 в 02:41