Closed viniciushss-interstar closed 3 years ago
The fastest way would be to use the closure option for groupBy()
and return the string value yourself.
I'm pretty sure/optimistic that things like this will get better with PHP8.1 native enums and the things we can do with them then.
$testModels->groupBy(fn(TestModel $m): string => $m->status->value));
Thank you, that worked nicely.
Hi there,
Sorry if I'm doing something wrong but there's a problem when using an enum as model attribute and the attribute is used in the method
groupBy
of a Eloquent Collection. Example:The model:
The problem with groupBy:
The return is:
If I remove the cast from the model, it works fine, using the value as array key. Any suggestions?
Thanks!