29.07.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Artisan Console 168<br />

.<br />

1 // Retrieve a specific option...<br />

2 $queueName = $this->option('queue');<br />

3<br />

4 // Retrieve all options...<br />

5 $options = $this->option();<br />

If the argument or option does not exist, null will be returned.<br />

Prompting For Input<br />

In addition to displaying output, you may also ask the user to provide input during the execution of<br />

your command. The ask method will prompt the user with the given question, accept their input,<br />

and then return the user’s input back to your command:<br />

.<br />

1 /**<br />

2 * Execute the console command.<br />

3 *<br />

4 * @return mixed<br />

5 */<br />

6 public function handle()<br />

7 {<br />

8 $name = $this->ask('What is your name?');<br />

9 }<br />

The secret method is similar to ask, but the user’s input will not be visible to them as they type in<br />

the console. This method is useful for asking for sensitive information such as a password:<br />

.<br />

1 $password = $this->secret('What is the password?');<br />

Asking For Confirmation<br />

If you need to ask the user for a simple confirmation, you may use the confirm method. By default,<br />

this method will return false. However, if the user enters y in response to the prompt, the method<br />

will return true.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!