Skip to content

Commit 32cc063

Browse files
committed
Merge branch '8.x'
# Conflicts: # documentation.md
2 parents 0559dfc + 6feb33f commit 32cc063

Some content is hidden

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

75 files changed

+1910
-343
lines changed

artisan.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- [Programmatically Executing Commands](#programmatically-executing-commands)
2020
- [Calling Commands From Other Commands](#calling-commands-from-other-commands)
2121
- [Stub Customization](#stub-customization)
22+
- [Events](#events)
2223

2324
<a name="introduction"></a>
2425
## Introduction
@@ -36,12 +37,16 @@ Every command also includes a "help" screen which displays and describes the com
3637

3738
Laravel Tinker is a powerful REPL for the Laravel framework, powered by the [PsySH](https://github.com/bobthecow/psysh) package.
3839

40+
<a name="installation"></a>
3941
#### Installation
4042

4143
All Laravel applications include Tinker by default. However, you may install it manually if needed using Composer:
4244

4345
composer require laravel/tinker
4446

47+
> {tip} Looking for a graphical UI for interacting with your Laravel application? Check out [Tinkerwell](https://tinkerwell.app)!
48+
49+
<a name="usage"></a>
4550
#### Usage
4651

4752
Tinker allows you to interact with your entire Laravel application on the command line, including the Eloquent ORM, jobs, events, and more. To enter the Tinker environment, run the `tinker` Artisan command:
@@ -54,6 +59,7 @@ You can publish Tinker's configuration file using the `vendor:publish` command:
5459

5560
> {note} The `dispatch` helper function and `dispatch` method on the `Dispatchable` class depends on garbage collection to place the job on the queue. Therefore, when using tinker, you should use `Bus::dispatch` or `Queue::push` to dispatch jobs.
5661
62+
<a name="command-whitelist"></a>
5763
#### Command Whitelist
5864

5965
Tinker utilizes a white-list to determine which Artisan commands are allowed to be run within its shell. By default, you may run the `clear-compiled`, `down`, `env`, `inspire`, `migrate`, `optimize`, and `up` commands. If you would like to white-list more commands you may add them to the `commands` array in your `tinker.php` configuration file:
@@ -62,6 +68,7 @@ Tinker utilizes a white-list to determine which Artisan commands are allowed to
6268
// App\Console\Commands\ExampleCommand::class,
6369
],
6470

71+
<a name="classes-that-should-not-be-aliased"></a>
6572
#### Classes That Should Not Be Aliased
6673

6774
Typically, Tinker automatically aliases classes as you require them in Tinker. However, you may wish to never alias some classes. You may accomplish this by listing the classes in the `dont_alias` array of your `tinker.php` configuration file:
@@ -160,6 +167,7 @@ Even though this file does not define HTTP routes, it defines console based entr
160167

161168
The Closure is bound to the underlying command instance, so you have full access to all of the helper methods you would typically be able to access on a full command class.
162169

170+
<a name="type-hinting-dependencies"></a>
163171
#### Type-Hinting Dependencies
164172

165173
In addition to receiving your command's arguments and options, command Closures may also type-hint additional dependencies that you would like resolved out of the [service container](/docs/{{version}}/container):
@@ -171,6 +179,7 @@ In addition to receiving your command's arguments and options, command Closures
171179
$drip->send(User::find($user));
172180
});
173181

182+
<a name="closure-command-descriptions"></a>
174183
#### Closure Command Descriptions
175184

176185
When defining a Closure based command, you may use the `describe` method to add a description to the command. This description will be displayed when you run the `php artisan list` or `php artisan help` commands:
@@ -331,6 +340,7 @@ The `secret` method is similar to `ask`, but the user's input will not be visibl
331340

332341
$password = $this->secret('What is the password?');
333342

343+
<a name="asking-for-confirmation"></a>
334344
#### Asking For Confirmation
335345

336346
If you need to ask the user for a simple confirmation, you may use the `confirm` method. By default, this method will return `false`. However, if the user enters `y` or `yes` in response to the prompt, the method will return `true`.
@@ -339,6 +349,7 @@ If you need to ask the user for a simple confirmation, you may use the `confirm`
339349
//
340350
}
341351

352+
<a name="auto-completion"></a>
342353
#### Auto-Completion
343354

344355
The `anticipate` method can be used to provide auto-completion for possible choices. The user can still choose any answer, regardless of the auto-completion hints:
@@ -351,6 +362,7 @@ Alternatively, you may pass a Closure as the second argument to the `anticipate`
351362
// Return auto-completion options...
352363
});
353364

365+
<a name="multiple-choice-questions"></a>
354366
#### Multiple Choice Questions
355367

356368
If you need to give the user a predefined set of choices, you may use the `choice` method. You may set the array index of the default value to be returned if no option is chosen:
@@ -390,6 +402,14 @@ If you would like to display plain, uncolored console output, use the `line` met
390402

391403
$this->line('Display this on the screen');
392404

405+
You may use the `newLine` method to display a blank line:
406+
407+
$this->newLine();
408+
409+
// Write three blank lines...
410+
$this->newLine(3);
411+
412+
<a name="table-layouts"></a>
393413
#### Table Layouts
394414

395415
The `table` method makes it easy to correctly format multiple rows / columns of data. Just pass in the headers and rows to the method. The width and height will be dynamically calculated based on the given data:
@@ -400,6 +420,7 @@ The `table` method makes it easy to correctly format multiple rows / columns of
400420

401421
$this->table($headers, $users);
402422

423+
<a name="progress-bars"></a>
403424
#### Progress Bars
404425

405426
For long running tasks, it could be helpful to show a progress indicator. Using the output object, we can start, advance and stop the Progress Bar. First, define the total number of steps the process will iterate through. Then, advance the Progress Bar after processing each item:
@@ -477,6 +498,7 @@ You may also specify the connection or queue the Artisan command should be dispa
477498
'user' => 1, '--queue' => 'default'
478499
])->onConnection('redis')->onQueue('commands');
479500

501+
<a name="passing-array-values"></a>
480502
#### Passing Array Values
481503

482504
If your command defines an option that accepts an array, you may pass an array of values to that option:
@@ -487,6 +509,7 @@ If your command defines an option that accepts an array, you may pass an array o
487509
]);
488510
});
489511

512+
<a name="passing-boolean-values"></a>
490513
#### Passing Boolean Values
491514

492515
If you need to specify the value of an option that does not accept string values, such as the `--force` flag on the `migrate:refresh` command, you should pass `true` or `false`:
@@ -528,3 +551,8 @@ The Artisan console's `make` commands are used to create a variety of classes, s
528551
php artisan stub:publish
529552

530553
The published stubs will be located within a `stubs` directory in the root of your application. Any changes you make to these stubs will be reflected when you generate their corresponding classes using Artisan `make` commands.
554+
555+
<a name="events"></a>
556+
## Events
557+
558+
Artisan dispatches three events when running commands: `Illuminate\Console\Events\ArtisanStarting`, `Illuminate\Console\Events\CommandStarting`, and `Illuminate\Console\Events\CommandFinished`. The `ArtisanStarting` event is dispatched immediately when Artisan starts running. Next, the `CommandStarting` event is dispatched immediately before a command runs. Finally, the `CommandFinished` event is dispatched once a command finishes executing.

0 commit comments

Comments
 (0)