Trait for easy manage useful datetime in entities.
Install by composer
composer require redrat/entity-datetime
1 - Add trait in your Entity
<?php
use RedRat\Entity\DateTimeTrait;
class Foo
{
use DateTimeTrait;
}
2 - Set lifecycleCallbacks
in your Doctrine configuration, like example below:
fields:
createdAt:
type: datetime
updatedAt:
type: datetime
nullable: true
lifecycleCallbacks:
prePersist: [ forgeCreatedAt ]
preUpdate: [ forgeUpdatedAt ]
Note: More about lifecycle callbacks in Doctrine documentation.
- API documentation.