#[PrePersist]
Lifecycle Callbacks
This content is for v1.0. Switch to the latest version for up-to-date documentation.
Run entity methods around persistence, update, removal, and hydration events.
Attributes
Section titled “Attributes”#[PrePersist]public function onPrePersist(): void{}
#[PostPersist]public function onPostPersist(): void{}Available callback attributes:
#[PostPersist]
#[PreUpdate]
#[PostUpdate]
#[PreRemove]
#[PostRemove]
#[PostLoad]
Use cases
Section titled “Use cases”- Set
created_atorupdated_attimestamps. - Write audit records after persistence.
- Validate entity state before flush.
- Normalize values after loading from the database.
- Mark soft-delete columns before removal.
#[PreUpdate]public function onPreUpdate(): void{ $this->updated_at = self::now();}
#[PostLoad]public function onPostLoad(): void{ $this->record('PostLoad');}