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
All of the configuration files for the Laravel framework are stored in the `config` directory. Each option is documented, so feel free to look through the files and get familiar with the options available to you.
17
18
19
+
These configuration files allow you to configure things like your database connection information, your mail server information, as well as various other core configuration values such as your application timezone and encryption key.
20
+
18
21
<aname="environment-configuration"></a>
19
22
## Environment Configuration
20
23
21
24
It is often helpful to have different configuration values based on the environment where the application is running. For example, you may wish to use a different cache driver locally than you do on your production server.
22
25
23
-
To make this a cinch, Laravel utilizes the [DotEnv](https://github.com/vlucas/phpdotenv) PHP library by Vance Lucas. In a fresh Laravel installation, the root directory of your application will contain a `.env.example` file. If you install Laravel via Composer, this file will automatically be copied to `.env`. Otherwise, you should copy the file manually.
26
+
To make this a cinch, Laravel utilizes the [DotEnv](https://github.com/vlucas/phpdotenv) PHP library. In a fresh Laravel installation, the root directory of your application will contain a `.env.example` file that defines many common environment variables. During the Laravel installation process, this file will automatically be copied to `.env`.
24
27
25
-
Your `.env` file should not be committed to your application's source control, since each developer / server using your application could require a different environment configuration. Furthermore, this would be a security risk in the event an intruder gains access to your source control repository, since any sensitive credentials would get exposed.
28
+
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.
26
29
27
-
If you are developing with a team, you may wish to continue including a `.env.example` file with your application. By putting placeholder values in the example configuration file, other developers on your team can clearly see which environment variables are needed to run your application. You may also create a `.env.testing` file. This file will override the `.env` file when running PHPUnit tests or executing Artisan commands with the `--env=testing` option.
30
+
If you are developing with a team, you may wish to continue including a `.env.example` file with your application. By putting placeholder values in the example configuration file, other developers on your team can clearly see which environment variables are needed to run your application.
28
31
29
32
> {tip} Any variable in your `.env` file can be overridden by external environment variables such as server-level or system-level environment variables.
30
33
34
+
<aname="environment-file-security"></a>
35
+
#### Environment File Security
36
+
37
+
Your `.env` file should not be committed to your application's source control, since each developer / server using your application could require a different environment configuration. Furthermore, this would be a security risk in the event an intruder gains access to your source control repository, since any sensitive credentials would get exposed.
38
+
31
39
<aname="environment-variable-types"></a>
32
40
### Environment Variable Types
33
41
34
-
All variables in your `.env` files are parsed as strings, so some reserved values have been created to allow you to return a wider range of types from the `env()` function:
42
+
All variables in your `.env` files are typically parsed as strings, so some reserved values have been created to allow you to return a wider range of types from the `env()` function:
35
43
36
44
`.env` Value | `env()` Value
37
45
------------- | -------------
@@ -44,27 +52,29 @@ empty | (string) ''
44
52
null | (null) null
45
53
(null) | (null) null
46
54
47
-
If you need to define an environment variable with a value that contains spaces, you may do so by enclosing the value in double quotes.
55
+
If you need to define an environment variable with a value that contains spaces, you may do so by enclosing the value in double quotes:
All of the variables listed in this file will be loaded into the `$_ENV` PHP super-global when your application receives a request. However, you may use the `env` helper to retrieve values from these variables in your configuration files. In fact, if you review the Laravel configuration files, you will notice several of the options already using this helper:
62
+
All of the variables listed in this file will be loaded into the `$_ENV` PHP super-global when your application receives a request. However, you may use the `env` helper 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 helper:
55
63
56
64
'debug' => env('APP_DEBUG', false),
57
65
58
-
The second value passed to the `env` function is the "default value". This value will be used if no environment variable exists for the given key.
66
+
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.
59
67
60
68
<aname="determining-the-current-environment"></a>
61
69
### Determining The Current Environment
62
70
63
71
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):
64
72
73
+
use Illuminate\Support\Facades\App;
74
+
65
75
$environment = App::environment();
66
76
67
-
You may also pass arguments to the `environment` method to check if the environment matches a given value. The method will return `true` if the environment matches any of the given values:
77
+
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:
68
78
69
79
if (App::environment('local')) {
70
80
// The environment is local
@@ -74,35 +84,7 @@ You may also pass arguments to the `environment` method to check if the environm
74
84
// The environment is either local OR staging...
75
85
}
76
86
77
-
> {tip} The current application environment detection can be overridden by a server-level `APP_ENV` environment variable. This can be useful when you need to share the same application for different environment configurations, so you can set up a given host to match a given environment in your server's configurations.
When an exception is uncaught and the `APP_DEBUG` environment variable is `true`, the debug page will show all environment variables and their contents. In some cases you may want to obscure certain variables. You may do this by updating the `debug_hide` option in your `config/app.php` configuration file.
83
-
84
-
Some variables are available in both the environment variables and the server / request data. Therefore, you may need to hide them for both `$_ENV` and `$_SERVER`:
85
-
86
-
return [
87
-
88
-
// ...
89
-
90
-
'debug_hide' => [
91
-
'_ENV' => [
92
-
'APP_KEY',
93
-
'DB_PASSWORD',
94
-
],
95
-
96
-
'_SERVER' => [
97
-
'APP_KEY',
98
-
'DB_PASSWORD',
99
-
],
100
-
101
-
'_POST' => [
102
-
'password',
103
-
],
104
-
],
105
-
];
87
+
> {tip} The current application environment detection can be overridden by defining a server-level `APP_ENV` environment variable.
106
88
107
89
<aname="accessing-configuration-values"></a>
108
90
## Accessing Configuration Values
@@ -121,12 +103,19 @@ To set configuration values at runtime, pass an array to the `config` helper:
121
103
<aname="configuration-caching"></a>
122
104
## Configuration Caching
123
105
124
-
To give your application a speed boost, you should cache all of your configuration files into a single file using the `config:cache` Artisan command. This will combine all of the configuration options for your application into a single file which will be loaded quickly by the framework.
106
+
To give your application a speed boost, you should cache all of your configuration files into a single file using the `config:cache` Artisan command. This will combine all of the configuration options for your application into a single file which can be quickly loaded by the framework.
125
107
126
-
You should typically run the `php artisan config:cache` command as part of your production deployment routine. The command should not be run during local development as configuration options will frequently need to be changed during the course of your application's development.
108
+
You should typically run the `php artisan config:cache` command as part of your production deployment process. The command should not be run during local development as configuration options will frequently need to be changed during the course of your application's development.
127
109
128
110
> {note} If you execute the `config:cache` command during your deployment process, you should be sure that you are only calling the `env` function from within your configuration files. Once the configuration has been cached, the `.env` file will not be loaded and all calls to the `env` function will return `null`.
129
111
112
+
<aname="debug-mode"></a>
113
+
## Debug Mode
114
+
115
+
The `debug` option in your `config/app.php` configuration file determines how much information about an error is actually displayed to the user. By default, this option is set to respect the value of the `APP_DEBUG` environment variable, which is stored in your `.env` file.
116
+
117
+
For local development, you should set the `APP_DEBUG` environment variable to `true`. **In your production environment, this value should always be `false`. If the variable is set to `true` in production, you risk exposing sensitive configuration values to your application's end users.**
118
+
130
119
<aname="maintenance-mode"></a>
131
120
## Maintenance Mode
132
121
@@ -186,4 +175,4 @@ While your application is in maintenance mode, no [queued jobs](/docs/{{version}
186
175
<aname="alternatives-to-maintenance-mode"></a>
187
176
#### Alternatives To Maintenance Mode
188
177
189
-
Since maintenance mode requires your application to have several seconds of downtime, consider alternatives like [Envoyer](https://envoyer.io) to accomplish zero-downtime deployment with Laravel.
178
+
Since maintenance mode requires your application to have several seconds of downtime, consider alternatives like [Laravel Vapor](https://vapor.laravel.com) and [Envoyer](https://envoyer.io) to accomplish zero-downtime deployment with Laravel.
In addition to simplifying HTTP testing, Laravel provides a simple API for testing console applications that ask for user input.
9
+
In addition to simplifying HTTP testing, Laravel provides a simple API for testing your application's [custom console commands](/docs/{{version}}/artisan).
10
10
11
-
<aname="expecting-input-and-output"></a>
12
-
## Expecting Input / Output
11
+
<aname="input-output-expectations"></a>
12
+
## Input / Output Expectations
13
13
14
14
Laravel allows you to easily "mock" user input for your console commands using the `expectsQuestion` method. In addition, you may specify the exit code and text that you expect to be output by the console command using the `assertExitCode` and `expectsOutput` methods. For example, consider the following console command:
15
15
16
16
Artisan::command('question', function () {
17
17
$name = $this->ask('What is your name?');
18
18
19
-
$language = $this->choice('Which language do you program in?', [
19
+
$language = $this->choice('Which language do you prefer?', [
20
20
'PHP',
21
21
'Ruby',
22
22
'Python',
23
23
]);
24
24
25
-
$this->line('Your name is '.$name.' and you program in '.$language.'.');
25
+
$this->line('Your name is '.$name.' and you prefer '.$language.'.');
26
26
});
27
27
28
-
You may test this command with the following test which utilizes the `expectsQuestion`, `expectsOutput`, and `assertExitCode` methods:
28
+
You may test this command with the following test which utilizes the `expectsQuestion`, `expectsOutput`, `doesntExpectOutput`, and `assertExitCode` methods:
29
29
30
30
/**
31
31
* Test a console command.
@@ -36,13 +36,31 @@ You may test this command with the following test which utilizes the `expectsQue
36
36
{
37
37
$this->artisan('question')
38
38
->expectsQuestion('What is your name?', 'Taylor Otwell')
39
-
->expectsQuestion('Which language do you program in?', 'PHP')
40
-
->expectsOutput('Your name is Taylor Otwell and you program in PHP.')
39
+
->expectsQuestion('Which language do you prefer?', 'PHP')
40
+
->expectsOutput('Your name is Taylor Otwell and you prefer PHP.')
41
+
->doesntExpectOutput('Your name is Taylor Otwell and you prefer Ruby.')
41
42
->assertExitCode(0);
42
43
}
43
44
45
+
<aname="confirmation-expectations"></a>
46
+
#### Confirmation Expectations
47
+
44
48
When writing a command which expects a confirmation in the form of a "yes" or "no" answer, you may utilize the `expectsConfirmation` method:
45
49
46
50
$this->artisan('module:import')
47
51
->expectsConfirmation('Do you really wish to run this command?', 'no')
48
52
->assertExitCode(1);
53
+
54
+
<aname="table-expectations"></a>
55
+
#### Table Expectations
56
+
57
+
If your command displays a table of information using Artisan's `table` method, it can be cumbersome to write output expectations for the entire table. Instead, you may use the `expectsTable` method. This method accepts the table's headers as its first argument and the table's data as its second argument:
0 commit comments