Skip to content

Instantly share code, notes, and snippets.

@tarlepp
Created March 18, 2024 16:00
Show Gist options
  • Save tarlepp/4cea037662e52042d41a8f8ef466ef37 to your computer and use it in GitHub Desktop.
Save tarlepp/4cea037662e52042d41a8f8ef466ef37 to your computer and use it in GitHub Desktop.
<?php
declare(strict_types = 1);
namespace App\Entity\Traits;
use DateTimeImmutable;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
trait Timestampable
{
#[ORM\Column(
name: 'created_at',
type: Types::DATETIME_IMMUTABLE,
nullable: true,
)]
#[Gedmo\Timestampable(
on: 'create',
)]
protected ?DateTimeImmutable $createdAt = null;
#[ORM\Column(
name: 'updated_at',
type: Types::DATETIME_IMMUTABLE,
nullable: true,
)]
#[Gedmo\Timestampable(
on: 'update',
)]
protected ?DateTimeImmutable $updatedAt = null;
public function setCreatedAt(DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getCreatedAt(): ?DateTimeImmutable
{
return $this->createdAt;
}
public function setUpdatedAt(DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getUpdatedAt(): ?DateTimeImmutable
{
return $this->updatedAt;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment