You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: configuration.md
+33-21Lines changed: 33 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -97,7 +97,9 @@ APP_NAME="My Application"
97
97
98
98
All of the variables listed in the `.env` file will be loaded into the `$_ENV` PHP super-global when your application receives a request. However, you may use the `env` function to retrieve values from these variables in your configuration files. In fact, if you review the Laravel configuration files, you will notice many of the options are already using this function:
99
99
100
-
'debug' => env('APP_DEBUG', false),
100
+
```php
101
+
'debug' => env('APP_DEBUG', false),
102
+
```
101
103
102
104
The second value passed to the `env` function is the "default value". This value will be returned if no environment variable exists for the given key.
103
105
@@ -106,19 +108,23 @@ The second value passed to the `env` function is the "default value". This value
106
108
107
109
The current application environment is determined via the `APP_ENV` variable from your `.env` file. You may access this value via the `environment` method on the `App`[facade](/docs/{{version}}/facades):
108
110
109
-
use Illuminate\Support\Facades\App;
111
+
```php
112
+
use Illuminate\Support\Facades\App;
110
113
111
-
$environment = App::environment();
114
+
$environment = App::environment();
115
+
```
112
116
113
117
You may also pass arguments to the `environment` method to determine if the environment matches a given value. The method will return `true` if the environment matches any of the given values:
114
118
115
-
if (App::environment('local')) {
116
-
// The environment is local
117
-
}
119
+
```php
120
+
if (App::environment('local')) {
121
+
// The environment is local
122
+
}
118
123
119
-
if (App::environment(['local', 'staging'])) {
120
-
// The environment is either local OR staging...
121
-
}
124
+
if (App::environment(['local', 'staging'])) {
125
+
// The environment is either local OR staging...
126
+
}
127
+
```
122
128
123
129
> [!NOTE]
124
130
> The current application environment detection can be overridden by defining a server-level `APP_ENV` environment variable.
You may easily access your configuration values using the `Config` facade or global `config` function from anywhere in your application. The configuration values may be accessed using "dot" syntax, which includes the name of the file and option you wish to access. A default value may also be specified and will be returned if the configuration option does not exist:
194
200
195
-
use Illuminate\Support\Facades\Config;
201
+
```php
202
+
use Illuminate\Support\Facades\Config;
196
203
197
-
$value = Config::get('app.timezone');
204
+
$value = Config::get('app.timezone');
198
205
199
-
$value = config('app.timezone');
206
+
$value = config('app.timezone');
200
207
201
-
// Retrieve a default value if the configuration value does not exist...
202
-
$value = config('app.timezone', 'Asia/Seoul');
208
+
// Retrieve a default value if the configuration value does not exist...
209
+
$value = config('app.timezone', 'Asia/Seoul');
210
+
```
203
211
204
212
To set configuration values at runtime, you may invoke the `Config` facade's `set` method or pass an array to the `config` function:
205
213
206
-
Config::set('app.timezone', 'America/Chicago');
214
+
```php
215
+
Config::set('app.timezone', 'America/Chicago');
207
216
208
-
config(['app.timezone' => 'America/Chicago']);
217
+
config(['app.timezone' => 'America/Chicago']);
218
+
```
209
219
210
220
To assist with static analysis, the `Config` facade also provides typed configuration retrieval methods. If the retrieved configuration value does not match the expected type, an exception will be thrown:
0 commit comments