composer require mapado/pretty-typesBased on Doctrine DBAL types.
Will store pretty printed JSON into database.
In your config file
# Doctrine Configuration
doctrine:
dbal:
types:
json_pretty: Mapado\PrettyTypes\JsonPrettyTypeIn your entities
/**
* ...
*
* @ORM\Column(name="column_name", type="json_pretty")
*/If you want to store datetime in UTC in your database.
Copied version from Working with DateTime Instances.
All credits goes to the doctrine team !
In your config file
# Doctrine Configuration
doctrine:
dbal:
types:
datetime: Mapado\PrettyTypes\UTCDateTimeType
datetime_immutable: Mapado\PrettyTypes\UTCDateTimeImmutableType
datetimetz: Mapado\PrettyTypes\UTCDateTimeTypeBe aware that this will override all datetimes configured with doctrine.
If you do not want to override everything and use a custom types instead:
# Doctrine Configuration
doctrine:
dbal:
types:
utcdatetime: Mapado\PrettyTypes\UTCDateTimeType
utc_datetime_immutable: Mapado\PrettyTypes\UTCDateTimeImmutableTypeIn your entities, if you overrode the default datetime types, Doctrine will implicitly use the new types for all datetime fields:
#[ORM\Column]
private \DateTime $someDate;
#[ORM\Column]
private \DateTimeImmutable $someDate;You should store the timezone next to the datetime too. Read the doctrine documentation for more informations.
If you configured a custom type, use this instead:
#[ORM\Column(type: 'utcdatetime')]
private \DateTime $someDate;
#[ORM\Column(type: 'utc_datetime_immutable')]
private \DateTimeImmutable $someDate;This project is licensed under the MIT license.