We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 574c453 + a5d2a2d commit 29ec296Copy full SHA for 29ec296
doctrine/events.rst
@@ -80,6 +80,29 @@ define a callback for the ``prePersist`` Doctrine event:
80
}
81
82
83
+ .. code-block:: php-attributes
84
+
85
+ // src/Entity/Product.php
86
+ namespace App\Entity;
87
88
+ use Doctrine\ORM\Mapping as ORM;
89
90
+ // When using attributes, don't forget to add #[ORM\HasLifecycleCallbacks]
91
+ // to the class of the entity where you define the callback
92
93
+ #[ORM\Entity]
94
+ #[ORM\HasLifecycleCallbacks]
95
+ class Product
96
+ {
97
+ // ...
98
99
+ #[ORM\PrePersist]
100
+ public function setCreatedAtValue(): void
101
102
+ $this->createdAt = new \DateTimeImmutable();
103
+ }
104
105
106
.. code-block:: yaml
107
108
# config/doctrine/Product.orm.yml
0 commit comments