foo_constants.php
or fooConstants.php
?
It seems laravel would do some name conversion when you use Config::get('...')
, which one do you use?
When you download laravel 9 framework you would see following laravel config files in config folder: Each file name in this directory refers to some specific module and module related configurations are stored as php array in this file. Let's take a look at the sample config file for config/service.php file:
Here is my overview of the best naming conventions for Laravel. (Please let me know in a comment if you disagree with anything here) Controllers should be in singular case, no spacing between words, and end with "Controller". Also, each word should be capitalised (i.e. BlogController, not blogcontroller).
Laravel's default .env file contains some common configuration values that may differ based on whether your application is running locally or on a production web server. These values are then retrieved from various Laravel configuration files within the config directory using Laravel's env function.
Follow PSR standards. Also, follow naming conventions accepted by Laravel community: new Class syntax creates tight coupling between classes and complicates testing. Use IoC container or facades instead. Pass the data to config files instead and then use the config () helper function to use the data in an application.
foo.php
Why specify constants
at all? Convention I've generally seen is single word filenames. I think in general most 'config' type settings will be constant in an environment even if it is variable between environments.
Take a look at the aws/aws-sdk-php-laravel composer package as an example. That file is named config.php
in the package, but gets published to aws.php
.
rydurham/Sentinel is another popular package. It also only has a single-word filename.
Update
In the situation you describe in your comment, I would do something like this:
<?php // File: foo.php
return [
'sheep' => [
'clothing' => 'wool',
'chews_on' => 'cud',
],
'wolf' => [
'clothing' => 'fur',
'chews_on' => 'sheep',
],
];
And you can access both of those via Config::get('foo.sheep')
and Config::get('foo.wolf')
, respectively. When they're defined on the server, they're still 'on the server' so to speak. If you wish to release the values stored in foo.sheep
to the public you can, and you can do so without also exposing foo.wolf
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With