I have enums that must have additional methods for translation purposes:
<?php
declare(strict_types=1);
namespace App\Enums;
enum GenderEnum: string
{
case MALE = 'male';
case FEMALE = 'female';
public function trans(): string
{
return trans('enums.' . $this->value);
}
}
This method is trans and it will be duplicated in all enums, how can I avoid duplication? I can't extend it using traits in enums.
Enum cannot be extended, and must not inherit
but you can use Traits, as long as the trait does not declare any properties
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