Closed Riaan-ZA closed 3 years ago
Hi @Riaan-ZA. This should already be the case, as can be seen here: https://github.com/simplesquid/nova-enum-field/blob/a059de0a2016487fb11853bdc49a458be925555f/src/Enum.php#L30-L33
Could you perhaps share more details of your setup?
I have
Enum::make('Type')->attachEnum(UserType::class),
in my config and
'user_type' => UserType::class,
in the $casts array in my model.
It resolves the values correctly in the forms, but on the listing, as well as the detail (which I just noticed) it's just ouputing the number value:
I'm using nova 3.15.0 and laravel 8
That's strange 🤔 I'll look into why it's doing that and get back to you.
Hi,
Instead of this:
protected $casts = [
'user_type' => UserType::class,
];
should be:
protected $enumCasts = [
'user_type' => UserType::class,
];
protected $casts = [
'user_type' => 'integer',
];
?
I don't think that's correct as least that's not working for me, both these docs and BenSampo docs say otherwise.
I does seem like there something wrong with my attribute casting though, since the return value is an integer and not an instance of \BenSampo\Enum\Enum
I think I've figured out the issue - just working on a solution now. We may have inadvertently introduced a breaking change in v2, so will probably have to release the fix with v3 (as the fix will then be a breaking change too). I'll keep you updated.
I've managed to get it fixed my side, the main issue was I wasn't using the BenSampo\Enum\Traits\CastsEnums
trait. After using that in combination with your suggestion above, it works.
Also tested just having:
protected $casts = [
'email_verified_at' => 'datetime',
'type' => UserType::class,
];
which works,
So not using the trait was my mistake
You're absolutely right! Let me update the README to include that, as I see I was doing the same thing from a fresh install... 😴
I have discovered a few things I'm going to change for v3 along the way, but at least we know it's not actually a bug!
Currently on the index listing page it just outputs the number, is it possible to show the resolved value there?