25 lines
567 B
PHP
25 lines
567 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Lewisdale\App\Models\Traits;
|
|
use DateTime;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
trait AutoUpdate
|
|
{
|
|
#[ORM\Column(type: 'datetime')]
|
|
protected DateTime $createdAt;
|
|
#[ORM\Column(type: 'datetime')]
|
|
protected DateTime $updatedAt;
|
|
|
|
#[ORM\PrePersist]
|
|
public function onPrePersist(): void {
|
|
$this->createdAt = new DateTime('now');
|
|
$this->updatedAt = new DateTime('now');
|
|
}
|
|
|
|
#[ORM\PreUpdate]
|
|
public function onPreUpdate(): void {
|
|
$this->updatedAt = new DateTime('now');
|
|
}
|
|
} |