I am using PHP 8.1.6, Symfony 6 with Doctrine ORM. I've been trying to get it to work for a long time but with no luck. I have followed tutorials but they are usually from other older versions of Symfony or Doctrine and those options do not work, I will thank greatly if someone can give me a little example to be able to make it work and understand it better.
You need to create your enum,
Please create your mapping class in the type
directory:
public function convertToPHPValue($value, AbstractPlatform $platform)
{
$enumClass = $this->getEnum();
return $enumClass::from($value);
}
public function convertToDatabaseValue($enum, AbstractPlatform $platform)
{
return $enum->value;
}
Please register in doctrine.yaml in your dbal types
types:
enumType: App\Doctrine\DBAL\Type\EnumType
In your Entity, you need to put the enumType in the orm column
and enum in your Entity type
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With