PHP Enum "Inheritance " in Filament
First off, I know you can't extend an enum in PHP, I'm trying to figure a way to accomplush that functionality though for the Filament
getLabel
, etc methods.
Lets say I have a base "Laravel" package that has among other things, an enum.
It's a plain 'ol, string backed enum. Nothing fancy.
If I then have a Filament plugin (package) that wants to use that enum, PHP lacking enum inheritance strikes again.
Does anyone have any preferred 'tricks' for 'extending (but not really)' an enum in this Filament package so that it has the getLabel
, getColor
, etc methods?
For example, the base Laravel package would have no Filament dependencies.
It could have an enum like
and in the Filament plugin that uses it, I'd like to have some way to 'add' the getLabel, etc to it.
In a dream world:
Been scratching my head at a clean way to solve this for a day or two. Just didn't know if anyone else had encountered this or knew of a good way to handle it. Thanks!4 Replies
trait!
enums cannot inherit in php
not sure if you can bind enums to laravel container
That's an interesting approach that I hadn't considered.
Well effectively the child package would need to 'inject' the trait into the base package's enum?
Because it'd be the child package that is 'defining' labels and colors via the Filament contract/methods.
But that will only work in places where the enum is resolved via container