Developer654079525's avatar

Custom config

Where to keep and how to access custom configuration key-value pairs? A fixed number of them that should be visible to all models and views. Is it a matter of just adding a new .php file to the config folder and returning an array? I need it to store some opcodes.

0 likes
3 replies
martinbean's avatar

@developer654079525 Yes, you can create additional files in the config directory.

Personally, I put any configuration for third-party services (like API keys etc) in the existing config/services.php file. But for opcodes, I would define an enum rather than putting it in a configuration file:

namespace App\Enumerations;

enum Opcode: int
{
    case Good = 0;
    case Bad = 1;
}

You could then reference the values using Opcode::Good or Opcode::Bad.

Use enums to define possible values like this.

2 likes
Developer654079525's avatar

What if the key-value pairs are string pairs? Wouldn't it then be much easier just to return an array of key-value pairs?

1 like

Please or to participate in this conversation.