Add mutator for amount field in Earning and Spending models
MODIFY
app/Earning.php
app/Earning.php
@@ -16,6 +16,17 @@ class Earning extends Model {
return ($secondsDifference / 60 / 60 / 24) . ' days ago';
}
+ // Mutators
+ public function setAmountAttribute($value) {
+ if (strpos($value, '.')) {
+ $mutated = str_replace('.', '', $value);
+ } else {
+ $mutated = $value * 100;
+ }
+
+ $this->attributes['amount'] = $mutated;
+ }
+
// Relations
//
}

MODIFY
app/Spending.php
app/Spending.php
@@ -16,6 +16,17 @@ class Spending extends Model {
return ($secondsDifference / 60 / 60 / 24) . ' days ago';
}
+ // Mutators
+ public function setAmountAttribute($value) {
+ if (strpos($value, '.')) {
+ $mutated = str_replace('.', '', $value);
+ } else {
+ $mutated = $value * 100;
+ }
+
+ $this->attributes['amount'] = $mutated;
+ }
+
// Relations
public function tag() {
return $this->belongsTo('App\Tag');

Add mutator for amount field in Earning and Spending models