Skip to content

Commit

Permalink
Fix for bug when attribute is null
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdicarlo committed Oct 24, 2020
1 parent 085b0cd commit f93666b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/HumanTimestamps.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public function __get($key)
// If the attribute does not end in the correct suffix, delegate to the
// default method on the parent. The date check is required to make
// sure the attribute is properly casted to a Carbon instance
if(Str::endsWith($key, '_for_humans') && $this->isDateAttribute(Str::beforeLast($key, '_for_humans'))) {
if(Str::endsWith($key, '_for_humans') && $this->getAttribute(Str::beforeLast($key, '_for_humans')) && $this->isDateAttribute(Str::beforeLast($key, '_for_humans'))) {
return $this->getAttribute(Str::beforeLast($key, '_for_humans'))->diffForHumans();
}

return parent::__get($key);
}

}
}

0 comments on commit f93666b

Please sign in to comment.