If you feel Config is costing you performance, you can try using the php artisan config:cache command. This will create a cache of your config, which means it's basically just loading an array (I believe) from a static file, which should be about as fast as possible. Also, you can use the Config facade or the config('app.something') helper function in order to access the value you want.
Aug 12, 2016
8
Level 2
Best place to store constants shared by multiple Controllers?
Hi,
The title pretty much says it. In Laravel, we can store all constants under Config, then use Config facade to access it. This is really convenient. But Config facade seems deprecated or may incur some performance costs. So what are the best way/practice store constants?
Please advise. Thanks in advance.
Zhiyong.
Level 20
I personally like to create a file called "constants.php" somewhere under the project tree then autoload it using composer. For example:
"autoload": {
"files": [
"src/App/constants.php"
]
}
Please or to participate in this conversation.