Artisan Console Flashcards

(25 cards)

1
Q

Type a terminal command, that displays every Artisan command!

A

php artisan list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which terminal command do you use to interact with Eloquent models in a project?

A

php artisan tinker

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Create an Artisan command named “SendEmails”!

A

php artisan make:command SendEmails

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Where can you change the functionality of an Artisan command, that you created?

A

In the commands class file under the handle() function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Assuming, that the user used a command incorrectly, which method do you need to use (assuming that you’ll put it in the correct place in the code) to return the exit code 1 and display an error message for the user?

A

$this->fail('Insert error message here.');

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which interface do you need to implement into your command’s class to stop more than one instance of the command from running at the same time?

A
use Illuminate\Contracts\Console\Isolatable;

class Example extends Command implements Isolatable
{ // ...
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

An isolated command will still exit with a successful exit status code when being ran, while another instance of it is running, even though the new instance won’t do anything. Run the Artisan command “mail:send 1”, which is an isolated command, and let it display the exit status code 12 if another instance of the command is already running!

A

php artisan mail:send 1 –isolated=12

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Given the command argument “mail:send {user}”, how can you make the user argument optional and how can you give that a default value?

A
// Optional argument...
'mail:send {user?}'

// Optional argument with default value...
'mail:send {user=example}'
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Create a boolean option for “mail:send {user}”, which is called “queue” and is true if it’s being passed!

A

‘mail:send {user} {–queue}’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Make an option for the command “mail:send {user}”, that is called “queue” and will receive values!

A

‘mail:send {user} {–queue=}’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Create the shortcut “Q” for the command ‘mail:send {user} {–queue}’!

A

‘mail:send {user} {–Q|queue}’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Modify this command ‘mail:send {user}’, so that it can include any amount of users (including 0)!

A

‘mail:send {user?*}’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Pass the IDs 1 and 2 to this command ‘mail:send {–id=*}’ using Artisan!

A

php artisan mail:send –id=1 –id=2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Using PromptsForMissingInput, create a function that returns the text “Which user ID should receive the mail?” if the argument “user” isn’t given!

A
protected function promptForMissingArgumentsUsing(): array
{
    return [
        'user' => 'Which user ID should receive the mail?',
    ];
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How could you define the variable “$userId” using the input for the argument “user”?

A

$userId = $this->argument('user');

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Retrieve all arguments entered into a command and define an array “$arguments” with them!

A

$arguments = $this->arguments();

17
Q

Define “$queueName” using what the user input as “queue”!

A

$queueName = $this->option('queue');

18
Q

Ask the user for their name during the execution of a command and save it to “$name”!

A

$name = $this->ask('What is your name?');

19
Q

Ask the user for their password during the execution of the command and save it to the variable “$password”!

A

$password = $this->secret('What is your password?');

20
Q

Make the user choose if they want to continue with the command they just entered!

A
if ($this->confirm('Do you wish to continue?')) {
    // ...
}
21
Q

Make the user choose between left or right Twix, name the variable that stores their chose “$side”!

A
$side = $this->choice(
    'Which Twix side tastes better?',
    ['Left', 'Right'],
    $defaultIndex
);
22
Q

How can you run an Artisan command within your code?

A
$exitCode = Artisan::call( // ...
);
23
Q

Run the Artisan command ‘mail:send’ in your code giving it the IDs 5 and 13 using the “–id” option!

A
$exitCode = Artisan::call('mail:send', [
    '--id' => [5, 13]
]);
24
Q

What do you need to do to add Artisan commands into your queue in your code?

A
Artisan::queue( // ...
);
25
How do you run an Artisan command from within the class of a different Artisan command?
``` $this->call( // insert other command with its arguments and options ); ```