Skip to content

Commit

Permalink
Update laravel userguide
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed Feb 17, 2016
1 parent f66c695 commit b69c80c
Show file tree
Hide file tree
Showing 51 changed files with 3,470 additions and 1,030 deletions.
27 changes: 19 additions & 8 deletions src/guide/laravel/artisan.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ Note that we are able to inject any dependencies we need into the command's cons
use App\User;
use App\DripEmailer;
use Illuminate\Console\Command;
use Illuminate\Foundation\Inspiring;

class Inspire extends Command
class SendEmails extends Command
{
/**
* The name and signature of the console command.
Expand Down Expand Up @@ -155,6 +154,16 @@ You may also assign default values to options:

email:send {user} {--queue=default}

To assign a shortcut when defining an option, you may specify it before the option name and use a | delimiter to separate the shortcut from the full option name:

email:send {user} {--Q|queue}

If you would like to define arguments or options to expect array inputs, you may use the `*` character:

email:send {user*}

email:send {user} {--id=*}

#### Input Descriptions

You may assign descriptions to input arguments and options by separating the parameter from the description using a colon:
Expand All @@ -173,8 +182,6 @@ You may assign descriptions to input arguments and options by separating the par

While your command is executing, you will obviously need to access the values for the arguments and options accepted by your command. To do so, you may use the `argument` and `option` methods:

To retrieve the value of an argument, use the `argument` method:

/**
* Execute the console command.
*
Expand Down Expand Up @@ -230,18 +237,18 @@ If you need to ask the user for a simple confirmation, you may use the `confirm`

#### Giving The User A Choice

The `anticipate` method can be used to provided autocompletion for possible choices. The user can still choose any answer, regardless of the choices.
The `anticipate` method can be used to provide autocompletion for possible choices. The user can still choose any answer, regardless of the auto-completion hints:

$name = $this->anticipate('What is your name?', ['Taylor', 'Dayle']);

If you need to give the user a predefined set of choices, you may use the `choice` method. The user chooses the index of the answer, but the value of the answer will be returned to you. You may set the default value to be returned if nothing is chosen:

$name = $this->choice('What is your name?', ['Taylor', 'Dayle'], false);
$name = $this->choice('What is your name?', ['Taylor', 'Dayle'], $default);

<a name="writing-output"></a>
### Writing Output

To send output to the console, use the `info`, `comment`, `question` and `error` methods. Each of these methods will use the appropriate ANSI colors for their purpose.
To send output to the console, use the `line`, `info`, `comment`, `question` and `error` methods. Each of these methods will use the appropriate ANSI colors for their purpose.

To display an information message to the user, use the `info` method. Typically, this will display in the console as green text:

Expand All @@ -259,6 +266,10 @@ To display an error message, use the `error` method. Error message text is typic

$this->error('Something went wrong!');

If you want to display plain console output, use the `line` method. The `line` method does not receive any unique coloration:

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

#### Table Layouts

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:
Expand Down Expand Up @@ -295,7 +306,7 @@ Once your command is finished, you need to register it with Artisan so it will b
Within this file, you will find a list of commands in the `commands` property. To register your command, simply add the class name to the list. When Artisan boots, all the commands listed in this property will be resolved by the [service container](/docs/{{version}}/container) and registered with Artisan:

protected $commands = [
'App\Console\Commands\SendEmails'
Commands\SendEmails::class
];

<a name="calling-commands-via-code"></a>
Expand Down
389 changes: 158 additions & 231 deletions src/guide/laravel/authentication.md

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions src/guide/laravel/authorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

In addition to providing [authentication](/docs/{{version}}/authentication) services out of the box, Laravel also provides a simple way to organize authorization logic and control access to resources. There are a variety of methods and helpers to assist you in organizing your authorization logic, and we'll cover each of them in this document.

> **Note:** Authorization was added in Laravel 5.1.11, please refer to the [upgrade guide](/docs/{{version}}/upgrade) before integrating these features into your application.
<a name="defining-abilities"></a>
## Defining Abilities

Expand All @@ -42,7 +40,7 @@ The simplest way to determine if a user may perform a given action is to define
*/
public function boot(GateContract $gate)
{
parent::registerPolicies($gate);
$this->registerPolicies($gate);

$gate->define('update-post', function ($user, $post) {
return $user->id === $post->user_id;
Expand All @@ -59,7 +57,8 @@ In addition to registering `Closures` as authorization callbacks, you may regist
$gate->define('update-post', 'Class@method');

<a name="intercepting-all-checks"></a>
#### Intercepting All Checks
<a name="intercepting-authorization-checks"></a>
#### Intercepting Authorization Checks

Sometimes, you may wish to grant all abilities to a specific user. For this situation, use the `before` method to define a callback that is run before all other authorization checks:

Expand All @@ -71,6 +70,12 @@ Sometimes, you may wish to grant all abilities to a specific user. For this situ

If the `before` callback returns a non-null result that result will be considered the result of the check.

You may use the `after` method to define a callback to be executed after every authorization check. However, you may not modify the result of the authorization check from an `after` callback:

$gate->after(function ($user, $ability, $result, $arguments) {
//
});

<a name="checking-abilities"></a>
## Checking Abilities

Expand Down Expand Up @@ -194,7 +199,7 @@ You may also combine the `@can` directive with `@else` directive:
<a name="within-form-requests"></a>
### Within Form Requests

You may also choose to utilize your `Gate` defined abilities from a [form request's](/docs/{{version}}/validation#form-request-validation) `authorize` method. For example, you may simply defer to the `Gate` within the form request's `authorize` method:
You may also choose to utilize your `Gate` defined abilities from a [form request's](/docs/{{version}}/validation#form-request-validation) `authorize` method. For example:

/**
* Determine if the user is authorized to make this request.
Expand Down Expand Up @@ -251,7 +256,7 @@ Once the policy exists, we need to register it with the `Gate` class. The `AuthS
*/
public function boot(GateContract $gate)
{
parent::registerPolicies($gate);
$this->registerPolicies($gate);
}
}

Expand Down
Loading

0 comments on commit b69c80c

Please sign in to comment.