formatitng

This commit is contained in:
Taylor Otwell 2018-08-05 08:35:14 -10:00
parent e0a01190cb
commit ca5c59ca1f
4 changed files with 7 additions and 24 deletions

View File

@ -54,7 +54,7 @@ After generating your command, you should fill in the `signature` and `descripti
> {tip} For greater code reuse, it is good practice to keep your console commands light and let them defer to application services to accomplish their tasks. In the example below, note that we inject a service class to do the "heavy lifting" of sending the e-mails.
Let's take a look at an example command. Note that we are able to inject any dependencies we need into the command's constructor (or in the `handle` method). The Laravel [service container](/docs/{{version}}/container) will automatically inject all dependencies type-hinted in the constructor (or in the `handle` method):
Let's take a look at an example command. Note that we are able to inject any dependencies we need into the command's constructor or `handle` method. The Laravel [service container](/docs/{{version}}/container) will automatically inject all dependencies type-hinted in the constructor or `handle` method:
<?php

View File

@ -25,32 +25,16 @@ To create a new middleware, use the `make:middleware` Artisan command:
php artisan make:middleware CheckAge
This command will place a new `CheckAge` class within your `app/Http/Middleware` directory. In this middleware, we will only allow access to the route if the supplied `age` is greater than 200. Otherwise, we will redirect the users back to the `home` URI.
This command will place a new `CheckAge` class within your `app/Http/Middleware` directory. In this middleware, we will only allow access to the route if the supplied `age` is greater than 200. Otherwise, we will redirect the users back to the `home` URI:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Routing\Redirector;
class CheckAge
{
/**
* @var Redirector
*/
private $redirector;
/**
* @param Redirector $redirector
* @return void
*/
public function __construct(Redirector $redirector)
{
// Dependencies automatically resolved by the service container...
$this->redirector = $redirector;
}
/**
* Handle an incoming request.
*
@ -61,7 +45,7 @@ This command will place a new `CheckAge` class within your `app/Http/Middleware`
public function handle($request, Closure $next)
{
if ($request->age <= 200) {
return $this->redirector->to('home');
return redirect('home');
}
return $next($request);

View File

@ -46,7 +46,7 @@ As an example, let's modify the default `DatabaseSeeder` class and add a databas
}
}
> {tip} You may type-hint any dependencies you need within the `run` method and they will be resolved via the [service container](/docs/{{version}}/container).
> {tip} You may type-hint any dependencies you need within the `run` method's signature. They will automatically be resolved via the Laravel [service container](/docs/{{version}}/container).
<a name="using-model-factories"></a>
### Using Model Factories

View File

@ -198,6 +198,8 @@ The generated class will be placed in the `app/Http/Requests` directory. If this
];
}
> {tip} You may type-hint any dependencies you need within the `rules` method's signature. They will automatically be resolved via the Laravel [service container](/docs/{{version}}/container).
So, how are the validation rules evaluated? All you need to do is type-hint the request on your controller method. The incoming form request is validated before the controller method is called, meaning you do not need to clutter your controller with any validation logic:
/**
@ -216,9 +218,6 @@ So, how are the validation rules evaluated? All you need to do is type-hint the
If validation fails, a redirect response will be generated to send the user back to their previous location. The errors will also be flashed to the session so they are available for display. If the request was an AJAX request, a HTTP response with a 422 status code will be returned to the user including a JSON representation of the validation errors.
> {tip} You may type-hint any dependencies you need within the `rules` method and they will be resolved via the [service container](/docs/{{version}}/container).
#### Adding After Hooks To Form Requests
If you would like to add an "after" hook to a form request, you may use the `withValidator` method. This method receives the fully constructed validator, allowing you to call any of its methods before the validation rules are actually evaluated:
@ -273,7 +272,7 @@ If you plan to have authorization logic in another part of your application, ret
return true;
}
> {tip} You may type-hint any dependencies you need within the `authorize` method and they will be resolved via the [service container](/docs/{{version}}/container).
> {tip} You may type-hint any dependencies you need within the `authorize` method's signature. They will automatically be resolved via the Laravel [service container](/docs/{{version}}/container).
<a name="customizing-the-error-messages"></a>
### Customizing The Error Messages