Closed WimWidgets closed 3 years ago
Hi @WimWidgets. By the looks of it, nullable enums aren't yet supported in the Enum itself (see BenSampo/laravel-enum#172). I would accept a PR to allow the field to be nullable if the previously mentioned PR is merged.
In the meantime, could you not just create a "Null" constant in your Enum class, like this?
final class UserType extends Enum
{
const Null = -1;
const Administrator = 0;
const Moderator = 1;
}
Hi,
I have the same problem but I have a string enum. What would it be the workaround for this case?
Thanks
I assume you could do something like const Null = 'NULL';
. You could also use the parseDatabase
method as described here: https://github.com/BenSampo/laravel-enum#casting-underlying-native-types
I'm closing this now as it seems the original issue and PR (BenSampo/laravel-enum#172) have both been closed.
It would be great if I could make the Enum field nullable. Even if I add
->nullable()
to my field configuration, the input can't be null, because of a hard-coded->rules('required', ...
in the Enum field class (line 25).