You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: artisan.md
+108-2Lines changed: 108 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,7 @@
12
12
-[Options](#options)
13
13
-[Input Arrays](#input-arrays)
14
14
-[Input Descriptions](#input-descriptions)
15
+
-[Prompting For Missing Input](#prompting-for-missing-input)
15
16
-[Command I/O](#command-io)
16
17
-[Retrieving Input](#retrieving-input)
17
18
-[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
231
232
php artisan mail:send 1 --isolated=12
232
233
```
233
234
235
+
<aname="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
+
234
250
<aname="lock-expiration-time"></a>
235
251
#### Lock Expiration Time
236
252
@@ -321,10 +337,10 @@ To assign a shortcut when defining an option, you may specify it before the opti
321
337
322
338
'mail:send {user} {--Q|queue}'
323
339
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:
325
341
326
342
```shell
327
-
php artisan mail:send 1 -Q
343
+
php artisan mail:send 1 -Qdefault
328
344
```
329
345
330
346
<aname="input-arrays"></a>
@@ -371,6 +387,93 @@ You may assign descriptions to input arguments and options by separating the arg
371
387
{user : The ID of the user}
372
388
{--queue : Whether the job should be queued}';
373
389
390
+
<aname="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:
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.
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
+
374
477
<aname="command-io"></a>
375
478
## Command I/O
376
479
@@ -402,6 +505,9 @@ Options may be retrieved just as easily as arguments using the `option` method.
402
505
<aname="prompting-for-input"></a>
403
506
### Prompting For Input
404
507
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
+
405
511
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:
Copy file name to clipboardExpand all lines: authentication.md
+12-16Lines changed: 12 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,7 @@ _Laravel Breeze_ is a simple, minimal implementation of all of Laravel's authent
80
80
81
81
_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.
82
82
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.
@@ -123,9 +123,9 @@ And, if you would like to get started quickly, we are pleased to recommend [Lara
123
123
124
124
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.
125
125
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.
127
127
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.
129
129
130
130
<aname="retrieving-the-authenticated-user"></a>
131
131
### Retrieving The Authenticated User
@@ -146,19 +146,21 @@ Alternatively, once a user is authenticated, you may access the authenticated us
146
146
147
147
namespace App\Http\Controllers;
148
148
149
+
use Illuminate\Http\RedirectResponse;
149
150
use Illuminate\Http\Request;
150
-
use Illuminate\Http\Response;
151
151
152
152
class FlightController extends Controller
153
153
{
154
154
/**
155
155
* Update the flight information for an existing flight.
156
156
*/
157
-
public function update(Request $request): Response
157
+
public function update(Request $request): RedirectResponse
158
158
{
159
-
// $request->user()
159
+
$user = $request->user();
160
+
161
+
// ...
160
162
161
-
return response()->noContent();
163
+
return redirect('/flights');
162
164
}
163
165
}
164
166
@@ -556,8 +558,6 @@ You may define your own authentication guards using the `extend` method on the `
556
558
*/
557
559
public function boot(): void
558
560
{
559
-
$this->registerPolicies();
560
-
561
561
Auth::extend('jwt', function (Application $app, string $name, array $config) {
562
562
// Return an instance of Illuminate\Contracts\Auth\Guard...
563
563
@@ -591,10 +591,8 @@ To get started, call the `Auth::viaRequest` method within the `boot` method of y
591
591
*/
592
592
public function boot(): void
593
593
{
594
-
$this->registerPolicies();
595
-
596
594
Auth::viaRequest('custom-token', function (Request $request) {
@@ -633,8 +631,6 @@ If you are not using a traditional relational database to store your users, you
633
631
*/
634
632
public function boot(): void
635
633
{
636
-
$this->registerPolicies();
637
-
638
634
Auth::provider('mongo', function (Application $app, array $config) {
639
635
// Return an instance of Illuminate\Contracts\Auth\UserProvider...
640
636
@@ -711,7 +707,7 @@ Now that we have explored each of the methods on the `UserProvider`, let's take
711
707
712
708
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.
713
709
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.
0 commit comments