I got error when trying to log activity with date format in my model.
protected static $logAttributes = ['expiration_date']
public function getExpirationDateAttribute($value)
{
if($value):
return \DateTime::createFromFormat($this->getDateFormat(), $value)->format('Y-m-d');
endif;
}
Symfony Component Debug Exception FatalThrowableError (E_ERROR)
Call to a member function format() on bool
How solve this problem ?
It seems like the datetime create method returns false instead of a datetime instance.
I recommend you to use the available Laravel logic like $casts, Carbon and the already available methods to handle dates on the model like asDateTime() and so on.
This is how we handle dates in this package - but I really recommend you to let Laravel cast this attribute and use the format method in your views or API resources who are responsible for displaying/formatting values in the wanted format.
I got this. Thanks!