Code Monkey home page Code Monkey logo

Comments (5)

BenSampo avatar BenSampo commented on May 20, 2024

@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. SuperAdministrator would become Super administrator.

Glad you find the package useful 👍

from laravel-enum.

BenSampo avatar BenSampo commented on May 20, 2024

@rsubr I've added a toSelectArray method. If you have any other methods that you often add to an enum, I've made the base Enum class macroable so you can extend it as you wish within your application.

https://github.com/BenSampo/laravel-enum#extending-the-enum-base-class

from laravel-enum.

rsubr avatar rsubr commented on May 20, 2024

@BenSampo works great! 🙏

Thanks for making it extensible.

You have even updated the project documentation! 😲 🏆

from laravel-enum.

rsubr avatar rsubr commented on May 20, 2024

Further testing shows that getDescription method defined in my UserType child class does not get called by toSelectArray. It's calling the method defined in the Enum base class function instead.

In the toSelectArray method, can you please change self::getDescription to static::getDescription so the overridden getDescription from the child class will be called?

There's the code that needs to be changed:

foreach ($array as $key => $value) {
//  $selectArray[$value] = self::getDescription($value);
    $selectArray[$value] = static::getDescription($value);
}

from laravel-enum.

BenSampo avatar BenSampo commented on May 20, 2024

@rsubr Yeah well spotted - have just pushed a fix for that.

from laravel-enum.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.