Skip to content
Advertisement

Update price column in database laravel

I am trying to pass along updated pricing to my orders table but am getting an error:

JavaScript

In my controller I have this:

JavaScript

The error is coming from the $newPaymentTotal that I want use to update the price that was in there before. That column is set up as a decimal as well.

Advertisement

Answer

Your line $request->session()->put('newPaymentTotal', $newPaymentTotal); never gets hit due to this issue:

JavaScript

In either case, you return a value before setting the session variable. You’ll need to move that to be before you call return

NOTE: Thats gonna cause a new error becuase $request isnt defined, you probably want request()->session()->put(.... there

That said, the whole method could be simplified using a ternary statement to something like:

JavaScript

On a related but off topic note:

Be very careful doing math with floating point numbers in PHP. And by careful, I really mean DONT do it. You WILL run into issues that cause very difficult to understand and trace back bugs. Instead, I ALWAYS do math by first converting all floats to an integer value, doing all the math needed with those integers, then converting back to a float for display purposes at the end.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement