Skip to content

Commit e1cf300

Browse files
committed
checking current attribute value for nullable before comparing
1 parent b6d192d commit e1cf300

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,12 @@ protected function originalIsEquivalent($key, $current)
986986
return true;
987987
}
988988

989+
// When check rich this check and current attribute value not equals with original, we should skip next steps
990+
// if current is null
991+
if (is_null($current)) {
992+
return false;
993+
}
994+
989995
if ($this->isDateAttribute($key)) {
990996
return $this->fromDateTime($current) === $this->fromDateTime($original);
991997
}

tests/Database/DatabaseEloquentModelTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,21 @@ public function testDirtyOnCastOrDateAttributes(){
7474
$model->foo = 1;
7575
$model->bar = '2017-03-18';
7676
$model->dateAttribute = '2017-03-18';
77+
$model->datetimeAttribute = '2017-03-23 22:17:00';
7778
$model->syncOriginal();
7879

80+
$model->boolAttribute = true;
7981
$model->foo = true;
8082
$model->bar = '2017-03-18 00:00:00';
81-
$model->boolAttribute = true;
8283
$model->dateAttribute = '2017-03-18 00:00:00';
84+
$model->datetimeAttribute = null;
8385

8486
$this->assertTrue($model->isDirty());
8587
$this->assertTrue($model->isDirty('foo'));
8688
$this->assertTrue($model->isDirty('bar'));
8789
$this->assertFalse($model->isDirty('boolAttribute'));
8890
$this->assertFalse($model->isDirty('dateAttribute'));
91+
$this->assertTrue($model->isDirty('datetimeAttribute'));
8992
}
9093

9194
public function testCleanAttributes()

0 commit comments

Comments
 (0)