Skip to content

Commit

Permalink
[12.x] use fenced code blocks (#10172)
Browse files Browse the repository at this point in the history
* use fenced code blocks

- better syntax highlighting
- easier copy/pasting of code examples
- consistency throughout docs block

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip
  • Loading branch information
browner12 authored Feb 19, 2025
1 parent 5496409 commit 1ab9932
Show file tree
Hide file tree
Showing 78 changed files with 25,389 additions and 18,768 deletions.
670 changes: 390 additions & 280 deletions artisan.md

Large diffs are not rendered by default.

602 changes: 339 additions & 263 deletions authentication.md

Large diffs are not rendered by default.

716 changes: 393 additions & 323 deletions authorization.md

Large diffs are not rendered by default.

1,808 changes: 1,076 additions & 732 deletions billing.md

Large diffs are not rendered by default.

432 changes: 238 additions & 194 deletions blade.md

Large diffs are not rendered by default.

474 changes: 263 additions & 211 deletions broadcasting.md

Large diffs are not rendered by default.

366 changes: 216 additions & 150 deletions cache.md

Large diffs are not rendered by default.

1,009 changes: 596 additions & 413 deletions cashier-paddle.md

Large diffs are not rendered by default.

3,550 changes: 1,991 additions & 1,559 deletions collections.md

Large diffs are not rendered by default.

54 changes: 33 additions & 21 deletions configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ APP_NAME="My Application"

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:

'debug' => env('APP_DEBUG', false),
```php
'debug' => env('APP_DEBUG', false),
```

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.

Expand All @@ -106,19 +108,23 @@ The second value passed to the `env` function is the "default value". This value

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

use Illuminate\Support\Facades\App;
```php
use Illuminate\Support\Facades\App;

$environment = App::environment();
$environment = App::environment();
```

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:

if (App::environment('local')) {
// The environment is local
}
```php
if (App::environment('local')) {
// The environment is local
}

if (App::environment(['local', 'staging'])) {
// The environment is either local OR staging...
}
if (App::environment(['local', 'staging'])) {
// The environment is either local OR staging...
}
```

> [!NOTE]
> The current application environment detection can be overridden by defining a server-level `APP_ENV` environment variable.
Expand Down Expand Up @@ -192,28 +198,34 @@ php artisan env:decrypt --force

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:

use Illuminate\Support\Facades\Config;
```php
use Illuminate\Support\Facades\Config;

$value = Config::get('app.timezone');
$value = Config::get('app.timezone');

$value = config('app.timezone');
$value = config('app.timezone');

// Retrieve a default value if the configuration value does not exist...
$value = config('app.timezone', 'Asia/Seoul');
// Retrieve a default value if the configuration value does not exist...
$value = config('app.timezone', 'Asia/Seoul');
```

To set configuration values at runtime, you may invoke the `Config` facade's `set` method or pass an array to the `config` function:

Config::set('app.timezone', 'America/Chicago');
```php
Config::set('app.timezone', 'America/Chicago');

config(['app.timezone' => 'America/Chicago']);
config(['app.timezone' => 'America/Chicago']);
```

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:

Config::string('config-key');
Config::integer('config-key');
Config::float('config-key');
Config::boolean('config-key');
Config::array('config-key');
```php
Config::string('config-key');
Config::integer('config-key');
Config::float('config-key');
Config::boolean('config-key');
Config::array('config-key');
```

<a name="configuration-caching"></a>
## Configuration Caching
Expand Down
56 changes: 33 additions & 23 deletions console-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,36 @@ public function test_console_command(): void

You may use the `assertNotExitCode` method to assert that the command did not exit with a given exit code:

$this->artisan('inspire')->assertNotExitCode(1);
```php
$this->artisan('inspire')->assertNotExitCode(1);
```

Of course, all terminal commands typically exit with a status code of `0` when they are successful and a non-zero exit code when they are not successful. Therefore, for convenience, you may utilize the `assertSuccessful` and `assertFailed` assertions to assert that a given command exited with a successful exit code or not:

$this->artisan('inspire')->assertSuccessful();
```php
$this->artisan('inspire')->assertSuccessful();

$this->artisan('inspire')->assertFailed();
$this->artisan('inspire')->assertFailed();
```

<a name="input-output-expectations"></a>
## Input / Output Expectations

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:

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

$language = $this->choice('Which language do you prefer?', [
'PHP',
'Ruby',
'Python',
]);
$language = $this->choice('Which language do you prefer?', [
'PHP',
'Ruby',
'Python',
]);

$this->line('Your name is '.$name.' and you prefer '.$language.'.');
});
$this->line('Your name is '.$name.' and you prefer '.$language.'.');
});
```

You may test this command with the following test:

Expand Down Expand Up @@ -165,23 +171,27 @@ public function test_console_command(): void

When writing a command which expects confirmation in the form of a "yes" or "no" answer, you may utilize the `expectsConfirmation` method:

$this->artisan('module:import')
->expectsConfirmation('Do you really wish to run this command?', 'no')
->assertExitCode(1);
```php
$this->artisan('module:import')
->expectsConfirmation('Do you really wish to run this command?', 'no')
->assertExitCode(1);
```

<a name="table-expectations"></a>
#### Table Expectations

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:

$this->artisan('users:all')
->expectsTable([
'ID',
'Email',
], [
[1, '[email protected]'],
[2, '[email protected]'],
]);
```php
$this->artisan('users:all')
->expectsTable([
'ID',
'Email',
], [
[1, '[email protected]'],
[2, '[email protected]'],
]);
```

<a name="console-events"></a>
## Console Events
Expand Down
Loading

0 comments on commit 1ab9932

Please sign in to comment.