I have the following code to calculate the total price of a profit order and it works just fine.
{{ number_format($order->quantity * $order->product->price, 0) }}
I want to add an extra price field for, for example a license price so if the user selected a license as well the price of that should be added to the code above but as not all products have a license price I need to make an if statement so that the price can be sum to this price only if the license price exist.
How can I do that?
PS: working with laravel 5.4
try this:
@if( ! empty($order->license_price))
{{ number_format($order->quantity * $order->product->price + $order->license_price, 0)}}
@else
{{ number_format($order->quantity * $order->product->price, 0) }}
@endif
You could use ternary operator:
number_format($order->quantity * $order->product->price + empty($order->license) ? 0 : $order->license, 0)