0

I have a project where I have one field that currently adds its contents to one field in my database with the name Total. What I would like to do is be able to submit the input to two fields (which is easy enough), but on the rare occasion, I would like it to default the second field (balance) to 0.

So, at the current moment, here is a portion of my controller:

    $shipment->noCharge = request('noCharge');
    $shipment->noSettle = request('noSettle');
    $shipment->Total = request('Total');

I would like to be able to do something like:

    $shipment->noCharge = request('noCharge');
    $shipment->noSettle = request('noSettle');
    $shipment->Total = request('Total');
    $shipment->Balance = 
      //if (request('noCharge') = 1)
      // 0.00
      //else if (request('noSettle') = 1)
      // 0.00
      //else
       request('Total');
      //

Obviously my above won't work, but I hope it properly portrays what I am trying to do.

2 Answers 2

1

Why not simply do with one variable

$shipment->noCharge = request('noCharge');
$shipment->noSettle = request('noSettle');
$shipment->Total = request('Total');
if ((request('noCharge') == 1) || (request('noSettle') == 1)){
   $balance = 0.00;
}else{
   $balance = request('Total');
}
$shipment->Balance = $balance;

OR with ternary operator

Sign up to request clarification or add additional context in comments.

Comments

0

are you hinting at something like this?

 $shipment->noCharge = request('noCharge');
    $shipment->noSettle = request('noSettle');
    $shipment->Total = request('Total');
      if (request('noCharge') == 1) {
        $shipment->Balance = 0.00;
      }else if (request('noSettle') == 1) {
        $shipment->Balance = 0.00; 
      }else {
        $shipment->Balance = request('Total');
      }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.