Skip to content

Commit 09aadb3

Browse files
Replace $dates casts with date casting through the $casts property
1 parent 521f6aa commit 09aadb3

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

src/Coders/Model/Factory.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,10 +459,6 @@ protected function body(Model $model)
459459
$body .= $this->class->field('casts', $model->getCasts(), ['before' => "\n"]);
460460
}
461461

462-
if ($model->hasDates()) {
463-
$body .= $this->class->field('dates', $model->getDates(), ['before' => "\n"]);
464-
}
465-
466462
if ($model->hasHidden() && $model->doesNotUseBaseFiles()) {
467463
$body .= $this->class->field('hidden', $model->getHidden(), ['before' => "\n"]);
468464
}

src/Coders/Model/Model.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,6 @@ class Model
6767
*/
6868
protected $mutations = [];
6969

70-
/**
71-
* @var array
72-
*/
73-
protected $dates = [];
74-
7570
/**
7671
* @var array
7772
*/
@@ -267,12 +262,8 @@ protected function parseColumn(Fluent $column)
267262
$cast = 'string';
268263
}
269264

270-
// Track dates
271-
if ($cast == 'date') {
272-
$this->dates[] = $propertyName;
273-
}
274-
// Track attribute casts
275-
elseif ($cast != 'string') {
265+
// Track attribute casts, ignoring timestamps
266+
if ($cast != 'string' && !in_array($propertyName, [$this->CREATED_AT, $this->UPDATED_AT])) {
276267
$this->casts[$propertyName] = $cast;
277268
}
278269

@@ -1001,7 +992,12 @@ public function hasDates()
1001992
*/
1002993
public function getDates()
1003994
{
1004-
return array_diff($this->dates, [$this->CREATED_AT, $this->UPDATED_AT]);
995+
return array_diff(
996+
array_filter($this->casts, function (string $cast) {
997+
return $cast === 'date';
998+
}),
999+
[$this->CREATED_AT, $this->UPDATED_AT]
1000+
);
10051001
}
10061002

10071003
/**

0 commit comments

Comments
 (0)