Skip to content

Commit c374962

Browse files
committed
Merge branch '10.x'
# Conflicts: # contributions.md # database.md # documentation.md # helpers.md # readme.md # releases.md # sail.md # upgrade.md
2 parents c58a6cb + 4e45170 commit c374962

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+7488
-3401
lines changed

artisan.md

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- [Options](#options)
1313
- [Input Arrays](#input-arrays)
1414
- [Input Descriptions](#input-descriptions)
15+
- [Prompting For Missing Input](#prompting-for-missing-input)
1516
- [Command I/O](#command-io)
1617
- [Retrieving Input](#retrieving-input)
1718
- [Prompting For Input](#prompting-for-input)
@@ -231,6 +232,21 @@ If you would like to specify the exit status code that the command should return
231232
php artisan mail:send 1 --isolated=12
232233
```
233234

235+
<a name="lock-id"></a>
236+
#### Lock ID
237+
238+
By default, Laravel will use the command's name to generate the string key that is used to acquire the atomic lock in your application's cache. However, you may customize this key by defining an `isolatableId` method on your Artisan command class, allowing you to integrate the command's arguments or options into the key:
239+
240+
```php
241+
/**
242+
* Get the isolatable ID for the command.
243+
*/
244+
public function isolatableId(): string
245+
{
246+
return $this->argument('user');
247+
}
248+
```
249+
234250
<a name="lock-expiration-time"></a>
235251
#### Lock Expiration Time
236252

@@ -321,10 +337,10 @@ To assign a shortcut when defining an option, you may specify it before the opti
321337

322338
'mail:send {user} {--Q|queue}'
323339

324-
When invoking the command on your terminal, option shortcuts should be prefixed with a single hyphen:
340+
When invoking the command on your terminal, option shortcuts should be prefixed with a single hyphen and no `=` character should be included when specifying a value for the option:
325341

326342
```shell
327-
php artisan mail:send 1 -Q
343+
php artisan mail:send 1 -Qdefault
328344
```
329345

330346
<a name="input-arrays"></a>
@@ -371,6 +387,93 @@ You may assign descriptions to input arguments and options by separating the arg
371387
{user : The ID of the user}
372388
{--queue : Whether the job should be queued}';
373389

390+
<a name="prompting-for-missing-input"></a>
391+
### Prompting For Missing Input
392+
393+
If your command contains required arguments, the user will receive an error message when they are not provided. Alternatively, you may configure your command to automatically prompt the user when required arguments are missing by implementing the `PromptsForMissingInput` interface:
394+
395+
<?php
396+
397+
namespace App\Console\Commands;
398+
399+
use Illuminate\Console\Command;
400+
use Illuminate\Contracts\Console\PromptsForMissingInput;
401+
402+
class SendEmails extends Command implements PromptsForMissingInput
403+
{
404+
/**
405+
* The name and signature of the console command.
406+
*
407+
* @var string
408+
*/
409+
protected $signature = 'mail:send {user}';
410+
411+
// ...
412+
}
413+
414+
If Laravel needs to gather a required argument from the user, it will automatically ask the user for the argument by intelligently phrasing the question using either the argument name or description. If you wish to customize the question used to gather the required argument, you may implement the `promptForMissingArgumentsUsing` method, returning an array of questions keyed by the argument names:
415+
416+
/**
417+
* Prompt for missing input arguments using the returned questions.
418+
*
419+
* @return array
420+
*/
421+
protected function promptForMissingArgumentsUsing()
422+
{
423+
return [
424+
'user' => 'Which user ID should receive the mail?',
425+
];
426+
}
427+
428+
You may also provide placeholder text by using a tuple containing the question and placeholder:
429+
430+
return [
431+
'user' => ['Which user ID should receive the mail?', 'E.g. 123'],
432+
];
433+
434+
If you would like complete control over the prompt, you may provide a closure that should prompt the user and return their answer:
435+
436+
use App\Models\User;
437+
use function Laravel\Prompts\search;
438+
439+
// ...
440+
441+
return [
442+
'user' => fn () => search(
443+
label: 'Search for a user:',
444+
placeholder: 'E.g. Taylor Otwell',
445+
options: fn ($value) => strlen($value) > 0
446+
? User::where('name', 'like', "%{$value}%")->pluck('name', 'id')->all()
447+
: []
448+
),
449+
];
450+
451+
> **Note**
452+
The comprehensive [Laravel Prompts](/docs/{{version}}/prompts) documentation includes additional information on the available prompts and their usage.
453+
454+
If you wish to prompt the user to select or enter [options](#options), you may include prompts in your command's `handle` method. However, if you only wish to prompt the user when they have also been automatically prompted for missing arguments, then you may implement the `afterPromptingForMissingArguments` method:
455+
456+
use Symfony\Component\Console\Input\InputInterface;
457+
use Symfony\Component\Console\Output\OutputInterface;
458+
use function Laravel\Prompts\confirm;
459+
460+
// ...
461+
462+
/**
463+
* Perform actions after the user was prompted for missing arguments.
464+
*
465+
* @param \Symfony\Component\Console\Input\InputInterface $input
466+
* @param \Symfony\Component\Console\Output\OutputInterface $output
467+
* @return void
468+
*/
469+
protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output)
470+
{
471+
$input->setOption('queue', confirm(
472+
label: 'Would you like to queue the mail?',
473+
default: $this->option('queue')
474+
));
475+
}
476+
374477
<a name="command-io"></a>
375478
## Command I/O
376479

@@ -402,6 +505,9 @@ Options may be retrieved just as easily as arguments using the `option` method.
402505
<a name="prompting-for-input"></a>
403506
### Prompting For Input
404507

508+
> **Note**
509+
> [Laravel Prompts](/docs/{{version}}/prompts) is a PHP package for adding beautiful and user-friendly forms to your command-line applications, with browser-like features including placeholder text and validation.
510+
405511
In addition to displaying output, you may also ask the user to provide input during the execution of your command. The `ask` method will prompt the user with the given question, accept their input, and then return the user's input back to your command:
406512

407513
/**

authentication.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ _Laravel Breeze_ is a simple, minimal implementation of all of Laravel's authent
8080

8181
_Laravel Fortify_ is a headless authentication backend for Laravel that implements many of the features found in this documentation, including cookie-based authentication as well as other features such as two-factor authentication and email verification. Fortify provides the authentication backend for Laravel Jetstream or may be used independently in combination with [Laravel Sanctum](/docs/{{version}}/sanctum) to provide authentication for an SPA that needs to authenticate with Laravel.
8282

83-
_[Laravel Jetstream](https://jetstream.laravel.com)_ is a robust application starter kit that consumes and exposes Laravel Fortify's authentication services with a beautiful, modern UI powered by [Tailwind CSS](https://tailwindcss.com), [Livewire](https://laravel-livewire.com), and / or [Inertia](https://inertiajs.com). Laravel Jetstream includes optional support for two-factor authentication, team support, browser session management, profile management, and built-in integration with [Laravel Sanctum](/docs/{{version}}/sanctum) to offer API token authentication. Laravel's API authentication offerings are discussed below.
83+
_[Laravel Jetstream](https://jetstream.laravel.com)_ is a robust application starter kit that consumes and exposes Laravel Fortify's authentication services with a beautiful, modern UI powered by [Tailwind CSS](https://tailwindcss.com), [Livewire](https://livewire.laravel.com), and / or [Inertia](https://inertiajs.com). Laravel Jetstream includes optional support for two-factor authentication, team support, browser session management, profile management, and built-in integration with [Laravel Sanctum](/docs/{{version}}/sanctum) to offer API token authentication. Laravel's API authentication offerings are discussed below.
8484

8585
<a name="laravels-api-authentication-services"></a>
8686
#### Laravel's API Authentication Services
@@ -123,9 +123,9 @@ And, if you would like to get started quickly, we are pleased to recommend [Lara
123123

124124
First, you should [install a Laravel application starter kit](/docs/{{version}}/starter-kits). Our current starter kits, Laravel Breeze and Laravel Jetstream, offer beautifully designed starting points for incorporating authentication into your fresh Laravel application.
125125

126-
Laravel Breeze is a minimal, simple implementation of all of Laravel's authentication features, including login, registration, password reset, email verification, and password confirmation. Laravel Breeze's view layer is made up of simple [Blade templates](/docs/{{version}}/blade) styled with [Tailwind CSS](https://tailwindcss.com). Breeze also offers an [Inertia](https://inertiajs.com) based scaffolding option using Vue or React.
126+
Laravel Breeze is a minimal, simple implementation of all of Laravel's authentication features, including login, registration, password reset, email verification, and password confirmation. Laravel Breeze's view layer is made up of simple [Blade templates](/docs/{{version}}/blade) styled with [Tailwind CSS](https://tailwindcss.com). Additionally, Breeze provides scaffolding options based on [Livewire](https://livewire.laravel.com) or [Inertia](https://inertiajs.com), with the choice of using Vue or React for the Inertia-based scaffolding.
127127

128-
[Laravel Jetstream](https://jetstream.laravel.com) is a more robust application starter kit that includes support for scaffolding your application with [Livewire](https://laravel-livewire.com) or [Inertia and Vue](https://inertiajs.com). In addition, Jetstream features optional support for two-factor authentication, teams, profile management, browser session management, API support via [Laravel Sanctum](/docs/{{version}}/sanctum), account deletion, and more.
128+
[Laravel Jetstream](https://jetstream.laravel.com) is a more robust application starter kit that includes support for scaffolding your application with [Livewire](https://livewire.laravel.com) or [Inertia and Vue](https://inertiajs.com). In addition, Jetstream features optional support for two-factor authentication, teams, profile management, browser session management, API support via [Laravel Sanctum](/docs/{{version}}/sanctum), account deletion, and more.
129129

130130
<a name="retrieving-the-authenticated-user"></a>
131131
### Retrieving The Authenticated User
@@ -146,19 +146,21 @@ Alternatively, once a user is authenticated, you may access the authenticated us
146146

147147
namespace App\Http\Controllers;
148148

149+
use Illuminate\Http\RedirectResponse;
149150
use Illuminate\Http\Request;
150-
use Illuminate\Http\Response;
151151

152152
class FlightController extends Controller
153153
{
154154
/**
155155
* Update the flight information for an existing flight.
156156
*/
157-
public function update(Request $request): Response
157+
public function update(Request $request): RedirectResponse
158158
{
159-
// $request->user()
159+
$user = $request->user();
160+
161+
// ...
160162

161-
return response()->noContent();
163+
return redirect('/flights');
162164
}
163165
}
164166

@@ -556,8 +558,6 @@ You may define your own authentication guards using the `extend` method on the `
556558
*/
557559
public function boot(): void
558560
{
559-
$this->registerPolicies();
560-
561561
Auth::extend('jwt', function (Application $app, string $name, array $config) {
562562
// Return an instance of Illuminate\Contracts\Auth\Guard...
563563

@@ -591,10 +591,8 @@ To get started, call the `Auth::viaRequest` method within the `boot` method of y
591591
*/
592592
public function boot(): void
593593
{
594-
$this->registerPolicies();
595-
596594
Auth::viaRequest('custom-token', function (Request $request) {
597-
return User::where('token', $request->token)->first();
595+
return User::where('token', (string) $request->token)->first();
598596
});
599597
}
600598

@@ -610,7 +608,7 @@ Finally, you may reference the guard when assigning the authentication middlewar
610608

611609
Route::middleware('auth:api')->group(function () {
612610
// ...
613-
}
611+
});
614612

615613
<a name="adding-custom-user-providers"></a>
616614
## Adding Custom User Providers
@@ -633,8 +631,6 @@ If you are not using a traditional relational database to store your users, you
633631
*/
634632
public function boot(): void
635633
{
636-
$this->registerPolicies();
637-
638634
Auth::provider('mongo', function (Application $app, array $config) {
639635
// Return an instance of Illuminate\Contracts\Auth\UserProvider...
640636

@@ -711,7 +707,7 @@ Now that we have explored each of the methods on the `UserProvider`, let's take
711707

712708
This interface is simple. The `getAuthIdentifierName` method should return the name of the "primary key" field of the user and the `getAuthIdentifier` method should return the "primary key" of the user. When using a MySQL back-end, this would likely be the auto-incrementing primary key assigned to the user record. The `getAuthPassword` method should return the user's hashed password.
713709

714-
This interface allows the authentication system to work with any "user" class, regardless of what ORM or storage abstraction layer you are using. By default, Laravel includes a `App\Models\User` class in the `app/Models` directory which implements this interface.
710+
This interface allows the authentication system to work with any "user" class, regardless of what ORM or storage abstraction layer you are using. By default, Laravel includes an `App\Models\User` class in the `app/Models` directory which implements this interface.
715711

716712
<a name="events"></a>
717713
## Events

0 commit comments

Comments
 (0)