marco.ferreira
Hi, I need help regarding validation. I want to validate multiple columns
You can use a unique rule with the where clause: https://laravel.com/docs/10.x/validation#rule-unique
something like this:
2 replies
Problem in the format_money helper
I probably am, but I don't understand how, or why. It seems obvious to me that all operations regarding money should be done using integers (in cents) precisely to avoid floating point errors. Using casts at the model layer has the effect of working directly with floats during calculations. If I have something like an invoice line with "quantity" and "price_without_taxes", and price_without_taxes is casted to float, when calculating the invoice total I'll introduce errors:
$total = 0;
foreach($invoice->lines as $line) {
$lineTotal = $line->price_without_taxes * $line->quantity; // 1st possible precision errors
$total += $lineTotal; // sum of rounding errors
6 replies
Problem in the format_money helper
Thanks for the pointer. But if I use the cast in the model, isn't it automatically converted to float on database read (and to int on write), making all my operations with that column be using floats, getting back to the original rounding and precision issues? I believe that this is a presentation problem, not a model problem. I'd still like to have the model always in cents, just present it in euros...
6 replies