Refactor date mutators

This commit is contained in:
David Bomba 2020-08-15 08:03:29 +10:00
parent cb24a89d00
commit da26a1f2f2
4 changed files with 21 additions and 39 deletions

View File

@ -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));

View File

@ -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');

View File

@ -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);

View File

@ -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);