Skip to content

Commit 6e7dc4c

Browse files
committed
Merge branch '5.7'
2 parents 915b322 + f499cfe commit 6e7dc4c

File tree

9 files changed

+367
-5
lines changed

9 files changed

+367
-5
lines changed

artisan.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Artisan Console
22

33
- [Introduction](#introduction)
4+
- [Tinker (REPL)](#tinker)
45
- [Writing Commands](#writing-commands)
56
- [Generating Commands](#generating-commands)
67
- [Command Structure](#command-structure)
@@ -29,12 +30,33 @@ Every command also includes a "help" screen which displays and describes the com
2930

3031
php artisan help migrate
3132

32-
#### Laravel REPL
33+
<a name="tinker"></a>
34+
### Tinker (REPL)
3335

3436
All Laravel applications include Tinker, a REPL powered by the [PsySH](https://github.com/bobthecow/psysh) package. 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:
3537

3638
php artisan tinker
3739

40+
You can publish Tinker's configuration file using the `vendor:publish` command:
41+
42+
php artisan vendor:publish --provider="Laravel\Tinker\TinkerServiceProvider"
43+
44+
#### Command Whitelist
45+
46+
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:
47+
48+
'commands' => [
49+
// App\Console\Commands\ExampleCommand::class,
50+
],
51+
52+
#### Alias Blacklist
53+
54+
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:
55+
56+
'dont_alias' => [
57+
App\User::class,
58+
],
59+
3860
<a name="writing-commands"></a>
3961
## Writing Commands
4062

@@ -365,7 +387,7 @@ For long running tasks, it could be helpful to show a progress indicator. Using
365387
$users = App\User::all();
366388

367389
$bar = $this->output->createProgressBar(count($users));
368-
390+
369391
$bar->start();
370392

371393
foreach ($users as $user) {

authentication.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ Laravel provides a quick way to scaffold all of the routes and views you need fo
6060

6161
This command should be used on fresh applications and will install a layout view, registration and login views, as well as routes for all authentication end-points. A `HomeController` will also be generated to handle post-login requests to your application's dashboard.
6262

63+
> {tip} If your application doesn’t need registration, you may disable it by removing the newly created `RegisterController` and modifying your route declaration: `Auth::routes(['register' => false]);`.
64+
6365
<a name="included-views"></a>
6466
### Views
6567

authorization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,13 @@ The `authorizeResource` method accepts the model's class name as its first argum
393393

394394
class PostController extends Controller
395395
{
396-
public function __constructor()
396+
public function __construct()
397397
{
398398
$this->authorizeResource(Post::class, 'post');
399399
}
400400
}
401401

402-
> {tip} You may use the `policy:make` command with the `--model` option to quickly generate a policy class for a given model: `php artisan policy:make --model=Post`.
402+
> {tip} You may use the `make:policy` command with the `--model` option to quickly generate a policy class for a given model: `php artisan make:policy PostPolicy --model=Post`.
403403
404404
<a name="via-blade-templates"></a>
405405
### Via Blade Templates

collections.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,13 @@ For the remainder of this documentation, we'll discuss each method available on
157157
[unique](#method-unique)
158158
[uniqueStrict](#method-uniquestrict)
159159
[unless](#method-unless)
160+
[unlessEmpty](#method-unlessempty)
161+
[unlessNotEmpty](#method-unlessnotempty)
160162
[unwrap](#method-unwrap)
161163
[values](#method-values)
162164
[when](#method-when)
165+
[whenEmpty](#method-whenempty)
166+
[whenNotEmpty](#method-whennotempty)
163167
[where](#method-where)
164168
[whereStrict](#method-wherestrict)
165169
[whereIn](#method-wherein)
@@ -1926,6 +1930,16 @@ The `unless` method will execute the given callback unless the first argument gi
19261930

19271931
For the inverse of `unless`, see the [`when`](#method-when) method.
19281932

1933+
<a name="method-unlessempty"></a>
1934+
#### `unlessEmpty()` {#collection-method}
1935+
1936+
Alias for the [`whenNotEmpty`](#method-whennotempty) method.
1937+
1938+
<a name="method-unlessnotempty"></a>
1939+
#### `unlessNotEmpty()` {#collection-method}
1940+
1941+
Alias for the [`whenEmpty`](#method-whenempty) method.
1942+
19291943
<a name="method-unwrap"></a>
19301944
#### `unwrap()` {#collection-method}
19311945

@@ -1985,6 +1999,88 @@ The `when` method will execute the given callback when the first argument given
19851999

19862000
For the inverse of `when`, see the [`unless`](#method-unless) method.
19872001

2002+
<a name="method-whenempty"></a>
2003+
#### `whenEmpty()` {#collection-method}
2004+
2005+
The `whenEmpty` method will execute the given callback when the collection is empty:
2006+
2007+
$collection = collect(['michael', 'tom']);
2008+
2009+
$collection->whenEmpty(function ($collection) {
2010+
return $collection->push('adam');
2011+
});
2012+
2013+
$collection->all();
2014+
2015+
// ['michael', 'tom']
2016+
2017+
2018+
$collection = collect();
2019+
2020+
$collection->whenEmpty(function ($collection) {
2021+
return $collection->push('adam');
2022+
});
2023+
2024+
$collection->all();
2025+
2026+
// ['adam']
2027+
2028+
2029+
$collection = collect(['michael', 'tom']);
2030+
2031+
$collection->whenEmpty(function($collection) {
2032+
return $collection->push('adam');
2033+
}, function($collection) {
2034+
return $collection->push('taylor');
2035+
});
2036+
2037+
$collection->all();
2038+
2039+
// ['michael', 'tom', 'taylor']
2040+
2041+
For the inverse of `whenEmpty`, see the [`whenNotEmpty`](#method-whennotempty) method.
2042+
2043+
<a name="method-whennotempty"></a>
2044+
#### `whenNotEmpty()` {#collection-method}
2045+
2046+
The `whenNotEmpty` method will execute the given callback when the collection is not empty:
2047+
2048+
$collection = collect(['michael', 'tom']);
2049+
2050+
$collection->whenNotEmpty(function ($collection) {
2051+
return $collection->push('adam');
2052+
});
2053+
2054+
$collection->all();
2055+
2056+
// ['michael', 'tom', 'adam']
2057+
2058+
2059+
$collection = collect();
2060+
2061+
$collection->whenNotEmpty(function ($collection) {
2062+
return $collection->push('adam');
2063+
});
2064+
2065+
$collection->all();
2066+
2067+
// []
2068+
2069+
2070+
$collection = collect();
2071+
2072+
$collection->whenNotEmpty(function($collection) {
2073+
return $collection->push('adam');
2074+
}, function($collection) {
2075+
return $collection->push('taylor');
2076+
});
2077+
2078+
$collection->all();
2079+
2080+
// ['taylor']
2081+
2082+
For the inverse of `whenNotEmpty`, see the [`whenEmpty`](#method-whenempty) method.
2083+
19882084
<a name="method-where"></a>
19892085
#### `where()` {#collection-method}
19902086

middleware.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [Global Middleware](#global-middleware)
77
- [Assigning Middleware To Routes](#assigning-middleware-to-routes)
88
- [Middleware Groups](#middleware-groups)
9+
- [Sorting Middleware](sorting-middleware)
910
- [Middleware Parameters](#middleware-parameters)
1011
- [Terminable Middleware](#terminable-middleware)
1112

@@ -185,6 +186,27 @@ Middleware groups may be assigned to routes and controller actions using the sam
185186

186187
> {tip} Out of the box, the `web` middleware group is automatically applied to your `routes/web.php` file by the `RouteServiceProvider`.
187188
189+
<a name="sorting-middleware"></a>
190+
### Sorting Middleware
191+
192+
Rarely, you may need your middleware to execute in a specific order but not have control over their order when they are assigned to the route. In this case, you may specify your middleware priority using the `$middlewarePriority` property of your `app/Http/Kernel.php` file:
193+
194+
/**
195+
* The priority-sorted list of middleware.
196+
*
197+
* This forces non-global middleware to always be in the given order.
198+
*
199+
* @var array
200+
*/
201+
protected $middlewarePriority = [
202+
\Illuminate\Session\Middleware\StartSession::class,
203+
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
204+
\App\Http\Middleware\Authenticate::class,
205+
\Illuminate\Session\Middleware\AuthenticateSession::class,
206+
\Illuminate\Routing\Middleware\SubstituteBindings::class,
207+
\Illuminate\Auth\Middleware\Authorize::class,
208+
];
209+
188210
<a name="middleware-parameters"></a>
189211
## Middleware Parameters
190212

queues.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ In this example, note that we were able to pass an [Eloquent model](/docs/{{vers
164164

165165
The `handle` method is called when the job is processed by the queue. Note that we are able to type-hint dependencies on the `handle` method of the job. The Laravel [service container](/docs/{{version}}/container) automatically injects these dependencies.
166166

167+
If you would like to take total control over how the container injects dependencies into the `handle` method, you may use the container's `bindMethod` method. The `bindMethod` method accepts a callback which receives the job and the container. Within the callback, you are free to invoke the `handle` method however you wish. Typically, you should call this method from a [service provider](/docs/{{version}}/providers):
168+
169+
use App\Jobs\ProcessPodcast;
170+
171+
$this->app->bindMethod(ProcessPodcast::class.'@handle', function ($job, $app) {
172+
return $job->handle($app->make(AudioProcessor::class));
173+
});
174+
167175
> {note} Binary data, such as raw image contents, should be passed through the `base64_encode` function before being passed to a queued job. Otherwise, the job may not properly serialize to JSON when being placed on the queue.
168176
169177
<a name="dispatching-jobs"></a>

routing.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,16 @@ Any HTML forms pointing to `POST`, `PUT`, or `DELETE` routes that are defined in
7676

7777
If you are defining a route that redirects to another URI, you may use the `Route::redirect` method. This method provides a convenient shortcut so that you do not have to define a full route or controller for performing a simple redirect:
7878

79+
Route::redirect('/here', '/there');
80+
81+
By default, `Route::redirect` returns a `302` status code. You may customize the status code using the optional third parameter:
82+
7983
Route::redirect('/here', '/there', 301);
8084

85+
You may use the `Route::permananentRedirect` method to return a `301` status code:
86+
87+
Route::permanentRedirect('/here', '/there');
88+
8189
<a name="view-routes"></a>
8290
### View Routes
8391

scheduling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ You may define all of your scheduled tasks in the `schedule` method of the `App\
3838

3939
namespace App\Console;
4040

41-
use DB;
41+
use Illuminate\Support\Facades\DB;
4242
use Illuminate\Console\Scheduling\Schedule;
4343
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
4444

0 commit comments

Comments
 (0)