Skip to content

Instantly share code, notes, and snippets.

@kaesetoast
Created February 7, 2021 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaesetoast/be4efec9d9d61f5d99f0c7214abedd89 to your computer and use it in GitHub Desktop.
Save kaesetoast/be4efec9d9d61f5d99f0c7214abedd89 to your computer and use it in GitHub Desktop.
<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiProperty;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
trait UuidTrait
{
/**
* @ORM\Column(type="uuid", unique=true)
* @ORM\Id
* @ApiProperty(identifier=true)
*/
protected $id;
/**
* @ORM\Column(type="datetime")
*/
protected $created_at;
public function __construct()
{
$this->id = Uuid::uuid4();
$this->setCreatedAt(new \DateTime());
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
* @return UuidTrait
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment