@jonjie Enums aren’t a replacement for configuration values.
ENUM vs Laravel Config
Just wondering what is the best option to store config/const variable while working with laravel? Since PHP8.1 already has ENUM, just thinking if it is best to switch from /config to ENUM.
@Jonjie well,
if the status of an order can be enumerated, i.e. is a finite set of known values, then go for an Enum.
But this is the kind of data that belongs to the application domain, it shouldn't be in a config file in the first place. Before PHP had proper Enums you could use class constants, or some package that emulated enums.
A config file, should hold values that can be changed to alter a parameter in the application without needing to touch the code. It is used to hold values that are environment dependent.
For example, a database credentials is something that does not change very often, but might be different on your local development machine and on your production server. The same for some API keys -- you can have an account for testing and other for production -- or cache configuration, storage paths...
It wouldn't be practical to change your application code every time you need to run your app in a different environment. It would also be a nightmare to version control it.
I don't think the set of possible order status is something that can change from environment to environment. And even if eventually you can add a new status, it would still belongs to the domain code, as this new status should be available to the app regardless of the environment it is running.
At least this is how I think of those =)
Please or to participate in this conversation.