In the database I have a salary for each of my staff.
I need to work out how much tax to deduct from the salary, but I don't think I would be correct to hardcode this into each view, something like...
{{($bob->salary - 12,000) * 0.2}}
It's obviously messy and repeated.
What I think I need to do is create a function where I can simply feed Bob's salary, it calculates the tax and returns the value.
Something like...
public function taxPayable($salary){
$taxThreshold = 12,000;
$taxRate = 0.2;
if($salary >= $taxThreshold){
$taxPayable = ($salary - $taxThreshold) * $taxRate;
} else {
$taxPayable = 0;
}
return $taxPayable;
}
Then simply..
{{Taxcalculator::taxPayable($bob->salary)}}
Would something like this be possible? Where would I put the function, in a controller or model? Obviosuly the code wouldn't work but just to show what I want to achieve, just wondering how I would achieve it, is this possible? thanks.