If statement within form input value
Hi,
How should I hand this? (see code below).
No value is being displayed, i guess because the if statement is within the " ".
<input type="text" class="form-control" value="
@if($product->salesprice > 0)
{{ round((($product->salesprice - (($price->amount*7.5)+($price->shipment_cost/$price->purchase_num)))/$product->salesprice)*100) }}
@endif
" disabled>
Instead of the if you should use a ternary operator.
<input type="text" class="form-control" value="{{ $product->salesprice > 0 ? round((($product->salesprice - (($price->amount*7.5)+($price->shipment_cost/$price->purchase_num)))/$product->salesprice)*100) : '' }}" disabled>
It might even be better to pull this calculation out of the input and put it above that, in a controller or somewhere else
<?php $price = $product->salesprice > 0
? round((($product->salesprice - (($price->amount*7.5)+($price->shipment_cost/$price->purchase_num)))/$product->salesprice)*100)
: null; ?>
<input type="text" class="form-control" value="{{ $price }}" disabled>
The PHP solution will fix it nicely I think :)
Thanks for the help.
Thank You
Ternary Operator solved my problem.
Please or to participate in this conversation.