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
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
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