-
-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need a toArray() fn that returns enum descriptions #21
Comments
@rsubr Yes, this looks good to me. I'll add something like it in when I get a chance. I was also thinking about making a better default for the getDescription method where it could guess a description for a key name e.g. Glad you find the package useful 👍 |
@rsubr I've added a https://github.com/BenSampo/laravel-enum#extending-the-enum-base-class |
@BenSampo works great! 🙏 Thanks for making it extensible. You have even updated the project documentation! 😲 🏆 |
Further testing shows that In the There's the code that needs to be changed: foreach ($array as $key => $value) {
// $selectArray[$value] = self::getDescription($value);
$selectArray[$value] = static::getDescription($value);
} |
@rsubr Yeah well spotted - have just pushed a fix for that. |
@BenSampo thanks a ton for this module and your blog post, using enums has greatly simplified my code.
I'm using enums to populate html
select
fields andtoArray()
almost satisfies my requirement. However, populating select field values with enum descriptions is more readable than using enum keys.eg. Instead of
SADMIN, AUTHOR
, the select field would show'Super Administrator', 'Blog Author'
.I'm now repeating the same
toArrayDescription()
function in all of my Enum classes as shown below. Can we have a toArrayDescription() added to laravel-enum to address this use case?The text was updated successfully, but these errors were encountered: