Skip to content

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.

#[PrePersist]
public function onPrePersist(): void
{
}
#[PostPersist]
public function onPostPersist(): void
{
}

Available callback attributes:

#[PrePersist]

#[PostPersist]

#[PreUpdate]

#[PostUpdate]

#[PreRemove]

#[PostRemove]

#[PostLoad]

  • Set created_at or updated_at timestamps.
  • 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');
}