Skip to content

Commit 0ab96f0

Browse files
authored
Documentation Revisions 2020 (#6625)
Massive updates to documentation for 2020.
1 parent 6ee4156 commit 0ab96f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+9786
-6750
lines changed

artisan.md

+149-109
Large diffs are not rendered by default.

authentication.md

+172-154
Large diffs are not rendered by default.

authorization.md

+245-134
Large diffs are not rendered by default.

billing.md

+365-275
Large diffs are not rendered by default.

blade.md

+434-306
Large diffs are not rendered by default.

broadcasting.md

+240-167
Large diffs are not rendered by default.

cache.md

+57-43
Large diffs are not rendered by default.

cashier-paddle.md

+280-196
Large diffs are not rendered by default.

collections.md

+246-134
Large diffs are not rendered by default.

configuration.md

+29-40
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,38 @@
88
- [Hiding Environment Variables From Debug Pages](#hiding-environment-variables-from-debug)
99
- [Accessing Configuration Values](#accessing-configuration-values)
1010
- [Configuration Caching](#configuration-caching)
11+
- [Debug Mode](#debug-mode)
1112
- [Maintenance Mode](#maintenance-mode)
1213

1314
<a name="introduction"></a>
1415
## Introduction
1516

1617
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.
1718

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+
1821
<a name="environment-configuration"></a>
1922
## Environment Configuration
2023

2124
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.
2225

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`.
2427

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.
2629

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.
2831

2932
> {tip} Any variable in your `.env` file can be overridden by external environment variables such as server-level or system-level environment variables.
3033
34+
<a name="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+
3139
<a name="environment-variable-types"></a>
3240
### Environment Variable Types
3341

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:
3543

3644
`.env` Value | `env()` Value
3745
------------- | -------------
@@ -44,27 +52,29 @@ empty | (string) ''
4452
null | (null) null
4553
(null) | (null) null
4654

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:
4856

4957
APP_NAME="My Application"
5058

5159
<a name="retrieving-environment-configuration"></a>
5260
### Retrieving Environment Configuration
5361

54-
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:
5563

5664
'debug' => env('APP_DEBUG', false),
5765

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.
5967

6068
<a name="determining-the-current-environment"></a>
6169
### Determining The Current Environment
6270

6371
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):
6472

73+
use Illuminate\Support\Facades\App;
74+
6575
$environment = App::environment();
6676

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:
6878

6979
if (App::environment('local')) {
7080
// The environment is local
@@ -74,35 +84,7 @@ You may also pass arguments to the `environment` method to check if the environm
7484
// The environment is either local OR staging...
7585
}
7686

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.
78-
79-
<a name="hiding-environment-variables-from-debug"></a>
80-
### Hiding Environment Variables From Debug Pages
81-
82-
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.
10688
10789
<a name="accessing-configuration-values"></a>
10890
## Accessing Configuration Values
@@ -121,12 +103,19 @@ To set configuration values at runtime, pass an array to the `config` helper:
121103
<a name="configuration-caching"></a>
122104
## Configuration Caching
123105

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.
125107

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.
127109

128110
> {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`.
129111
112+
<a name="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+
130119
<a name="maintenance-mode"></a>
131120
## Maintenance Mode
132121

@@ -186,4 +175,4 @@ While your application is in maintenance mode, no [queued jobs](/docs/{{version}
186175
<a name="alternatives-to-maintenance-mode"></a>
187176
#### Alternatives To Maintenance Mode
188177

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.

console-tests.md

+27-9
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
# Console Tests
22

33
- [Introduction](#introduction)
4-
- [Expecting Input / Output](#expecting-input-and-output)
4+
- [Input / Output Expectations](#input-output-expectations)
55

66
<a name="introduction"></a>
77
## Introduction
88

9-
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).
1010

11-
<a name="expecting-input-and-output"></a>
12-
## Expecting Input / Output
11+
<a name="input-output-expectations"></a>
12+
## Input / Output Expectations
1313

1414
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:
1515

1616
Artisan::command('question', function () {
1717
$name = $this->ask('What is your name?');
1818

19-
$language = $this->choice('Which language do you program in?', [
19+
$language = $this->choice('Which language do you prefer?', [
2020
'PHP',
2121
'Ruby',
2222
'Python',
2323
]);
2424

25-
$this->line('Your name is '.$name.' and you program in '.$language.'.');
25+
$this->line('Your name is '.$name.' and you prefer '.$language.'.');
2626
});
2727

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:
2929

3030
/**
3131
* Test a console command.
@@ -36,13 +36,31 @@ You may test this command with the following test which utilizes the `expectsQue
3636
{
3737
$this->artisan('question')
3838
->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.')
4142
->assertExitCode(0);
4243
}
4344

45+
<a name="confirmation-expectations"></a>
46+
#### Confirmation Expectations
47+
4448
When writing a command which expects a confirmation in the form of a "yes" or "no" answer, you may utilize the `expectsConfirmation` method:
4549

4650
$this->artisan('module:import')
4751
->expectsConfirmation('Do you really wish to run this command?', 'no')
4852
->assertExitCode(1);
53+
54+
<a name="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:
58+
59+
$this->artisan('users:all')
60+
->expectsTable([
61+
'ID',
62+
'Email',
63+
], [
64+
65+
66+
]);

0 commit comments

Comments
 (0)