diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index 927eaad6923e..78b1d9807614 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -50,6 +50,15 @@ class BaseModel extends Model return $this->encodePrimaryKey($this->id); } + public function dateMutatorw($value) + { + if (!empty($value)) { + return (new Carbon($value))->format('Y-m-d'); + } + + return $value; + } + public function __call($method, $params) { $entity = strtolower(class_basename($this)); diff --git a/app/Models/Credit.php b/app/Models/Credit.php index 3f6aed94c7ce..1a1a6c9ddf5d 100644 --- a/app/Models/Credit.php +++ b/app/Models/Credit.php @@ -95,28 +95,20 @@ class Credit extends BaseModel public function getDateAttribute($value) { - if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); - } - return $value; + return $this->dateMutator($value); } public function getDueDateAttribute($value) { - if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); - } - return $value; + return $this->dateMutator($value); } public function getPartialDueDateAttribute($value) { - if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); - } - return $value; + return $this->dateMutator($value); } + public function assigned_user() { return $this->belongsTo(User::class, 'assigned_user_id', 'id'); diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index f21364d1b483..84d034c71255 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -141,28 +141,20 @@ class Invoice extends BaseModel public function getDateAttribute($value) { - if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); - } - return $value; + return $this->dateMutator($value); } public function getDueDateAttribute($value) { - if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); - } - return $value; + return $this->dateMutator($value); } public function getPartialDueDateAttribute($value) { - if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); - } - return $value; + return $this->dateMutator($value); } + public function company() { return $this->belongsTo(Company::class); diff --git a/app/Models/Quote.php b/app/Models/Quote.php index 0f17db4712b2..a2c2deb9ed15 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -102,31 +102,20 @@ class Quote extends BaseModel public function getDateAttribute($value) { - if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); - } - - return $value; + return $this->dateMutator($value); } public function getDueDateAttribute($value) { - if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); - } - - return $value; + return $this->dateMutator($value); } public function getPartialDueDateAttribute($value) { - if (!empty($value)) { - return (new Carbon($value))->format('Y-m-d'); - } - - return $value; + return $this->dateMutator($value); } + public function company() { return $this->belongsTo(Company::class);