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: original-en/cache.md
+15-7Lines changed: 15 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -410,30 +410,38 @@ cache()->remember('users', $seconds, function () {
410
410
411
411
Cache tags allow you to tag related items in the cache and then flush all cached values that have been assigned a given tag. You may access a tagged cache by passing in an ordered array of tag names. For example, let's access a tagged cache and `put` a value into the cache:
Items stored via tags may not be accessed without also providing the tags that were used to store the value. To retrieve a tagged cache item, pass the same ordered list of tags to the `tags` method, then call the `get` method with the key you wish to retrieve:
You may flush all items that are assigned a tag or list of tags. For example, the following code would remove all caches tagged with either `people`, `authors`, or both. So, both `Anne` and `John` would be removed from the cache:
431
435
432
-
Cache::tags(['people', 'authors'])->flush();
436
+
```php
437
+
Cache::tags(['people', 'authors'])->flush();
438
+
```
433
439
434
440
In contrast, the code below would remove only cached values tagged with `authors`, so `Anne` would be removed, but not `John`:
@@ -217,7 +217,7 @@ By default, Fortify will throttle authentication attempts using the `EnsureLogin
217
217
Some applications may require a different approach to throttling authentication attempts, such as throttling by IP address alone. Therefore, Fortify allows you to specify your own [rate limiter](/docs/{{version}}/routing#rate-limiting) via the `fortify.limiters.login` configuration option. Of course, this configuration option is located in your application's `config/fortify.php` configuration file.
218
218
219
219
> [!NOTE]
220
-
> Utilizing a mixture of throttling, [twofactor authentication](/docs/{{version}}/fortify#two-factor-authentication), and an external web application firewall (WAF) will provide the most robust defense for your legitimate application users.
220
+
> Utilizing a mixture of throttling, [two-factor authentication](/docs/{{version}}/fortify#two-factor-authentication), and an external web application firewall (WAF) will provide the most robust defense for your legitimate application users.
@@ -244,9 +244,9 @@ public function register(): void
244
244
```
245
245
246
246
<aname="two-factor-authentication"></a>
247
-
## TwoFactor Authentication
247
+
## Two-Factor Authentication
248
248
249
-
When Fortify's twofactor authentication feature is enabled, the user is required to input a six digit numeric token during the authentication process. This token is generated using a time-based one-time password (TOTP) that can be retrieved from any TOTP compatible mobile authentication application such as Google Authenticator.
249
+
When Fortify's two-factor authentication feature is enabled, the user is required to input a six digit numeric token during the authentication process. This token is generated using a time-based one-time password (TOTP) that can be retrieved from any TOTP compatible mobile authentication application such as Google Authenticator.
250
250
251
251
Before getting started, you should first ensure that your application's `App\Models\User` model uses the `Laravel\Fortify\TwoFactorAuthenticatable` trait:
252
252
@@ -265,54 +265,54 @@ class User extends Authenticatable
265
265
}
266
266
```
267
267
268
-
Next, you should build a screen within your application where users can manage their twofactor authentication settings. This screen should allow the user to enable and disable twofactor authentication, as well as regenerate their twofactor authentication recovery codes.
268
+
Next, you should build a screen within your application where users can manage their two-factor authentication settings. This screen should allow the user to enable and disable two-factor authentication, as well as regenerate their two-factor authentication recovery codes.
269
269
270
-
> By default, the `features` array of the `fortify` configuration file instructs Fortify's twofactor authentication settings to require password confirmation before modification. Therefore, your application should implement Fortify's [password confirmation](#password-confirmation) feature before continuing.
270
+
> By default, the `features` array of the `fortify` configuration file instructs Fortify's two-factor authentication settings to require password confirmation before modification. Therefore, your application should implement Fortify's [password confirmation](#password-confirmation) feature before continuing.
271
271
272
272
<aname="enabling-two-factor-authentication"></a>
273
-
### Enabling TwoFactor Authentication
273
+
### Enabling Two-Factor Authentication
274
274
275
-
To begin enabling twofactor authentication, your application should make a POST request to the `/user/two-factor-authentication` endpoint defined by Fortify. If the request is successful, the user will be redirected back to the previous URL and the `status` session variable will be set to `two-factor-authentication-enabled`. You may detect this `status` session variable within your templates to display the appropriate success message. If the request was an XHR request, `200` HTTP response will be returned.
275
+
To begin enabling two-factor authentication, your application should make a POST request to the `/user/two-factor-authentication` endpoint defined by Fortify. If the request is successful, the user will be redirected back to the previous URL and the `status` session variable will be set to `two-factor-authentication-enabled`. You may detect this `status` session variable within your templates to display the appropriate success message. If the request was an XHR request, `200` HTTP response will be returned.
276
276
277
-
After choosing to enable twofactor authentication, the user must still "confirm" their twofactor authentication configuration by providing a valid twofactor authentication code. So, your "success" message should instruct the user that twofactor authentication confirmation is still required:
277
+
After choosing to enable two-factor authentication, the user must still "confirm" their two-factor authentication configuration by providing a valid two-factor authentication code. So, your "success" message should instruct the user that two-factor authentication confirmation is still required:
Next, you should display the twofactor authentication QR code for the user to scan into their authenticator application. If you are using Blade to render your application's frontend, you may retrieve the QR code SVG using the `twoFactorQrCodeSvg` method available on the user instance:
287
+
Next, you should display the two-factor authentication QR code for the user to scan into their authenticator application. If you are using Blade to render your application's frontend, you may retrieve the QR code SVG using the `twoFactorQrCodeSvg` method available on the user instance:
288
288
289
289
```php
290
290
$request->user()->twoFactorQrCodeSvg();
291
291
```
292
292
293
-
If you are building a JavaScript powered frontend, you may make an XHR GET request to the `/user/two-factor-qr-code` endpoint to retrieve the user's twofactor authentication QR code. This endpoint will return a JSON object containing an `svg` key.
293
+
If you are building a JavaScript powered frontend, you may make an XHR GET request to the `/user/two-factor-qr-code` endpoint to retrieve the user's two-factor authentication QR code. This endpoint will return a JSON object containing an `svg` key.
In addition to displaying the user's twofactor authentication QR code, you should provide a text input where the user can supply a valid authentication code to "confirm" their twofactor authentication configuration. This code should be provided to the Laravel application via a POST request to the `/user/confirmed-two-factor-authentication` endpoint defined by Fortify.
298
+
In addition to displaying the user's two-factor authentication QR code, you should provide a text input where the user can supply a valid authentication code to "confirm" their two-factor authentication configuration. This code should be provided to the Laravel application via a POST request to the `/user/confirmed-two-factor-authentication` endpoint defined by Fortify.
299
299
300
300
If the request is successful, the user will be redirected back to the previous URL and the `status` session variable will be set to `two-factor-authentication-confirmed`:
Twofactor authentication confirmed and enabled successfully.
305
+
Two-factor authentication confirmed and enabled successfully.
306
306
</div>
307
307
@endif
308
308
```
309
309
310
-
If the request to the twofactor authentication confirmation endpoint was made via an XHR request, a `200` HTTP response will be returned.
310
+
If the request to the two-factor authentication confirmation endpoint was made via an XHR request, a `200` HTTP response will be returned.
311
311
312
312
<aname="displaying-the-recovery-codes"></a>
313
313
#### Displaying the Recovery Codes
314
314
315
-
You should also display the user's twofactor recovery codes. These recovery codes allow the user to authenticate if they lose access to their mobile device. If you are using Blade to render your application's frontend, you may access the recovery codes via the authenticated user instance:
315
+
You should also display the user's two-factor recovery codes. These recovery codes allow the user to authenticate if they lose access to their mobile device. If you are using Blade to render your application's frontend, you may access the recovery codes via the authenticated user instance:
316
316
317
317
```php
318
318
(array) $request->user()->recoveryCodes()
@@ -323,11 +323,11 @@ If you are building a JavaScript powered frontend, you may make an XHR GET reque
323
323
To regenerate the user's recovery codes, your application should make a POST request to the `/user/two-factor-recovery-codes` endpoint.
During the authentication process, Fortify will automatically redirect the user to your application's twofactor authentication challenge screen. However, if your application is making an XHR login request, the JSON response returned after a successful authentication attempt will contain a JSON object that has a `two_factor` boolean property. You should inspect this value to know whether you should redirect to your application's twofactor authentication challenge screen.
328
+
During the authentication process, Fortify will automatically redirect the user to your application's two-factor authentication challenge screen. However, if your application is making an XHR login request, the JSON response returned after a successful authentication attempt will contain a JSON object that has a `two_factor` boolean property. You should inspect this value to know whether you should redirect to your application's two-factor authentication challenge screen.
329
329
330
-
To begin implementing twofactor authentication functionality, we need to instruct Fortify how to return our twofactor authentication challenge view. All of Fortify's authentication view rendering logic may be customized using the appropriate methods available via the `Laravel\Fortify\Fortify` class. Typically, you should call this method from the `boot` method of your application's `App\Providers\FortifyServiceProvider` class:
330
+
To begin implementing two-factor authentication functionality, we need to instruct Fortify how to return our two-factor authentication challenge view. All of Fortify's authentication view rendering logic may be customized using the appropriate methods available via the `Laravel\Fortify\Fortify` class. Typically, you should call this method from the `boot` method of your application's `App\Providers\FortifyServiceProvider` class:
331
331
332
332
```php
333
333
use Laravel\Fortify\Fortify;
@@ -349,12 +349,12 @@ Fortify will take care of defining the `/two-factor-challenge` route that return
349
349
350
350
If the login attempt is successful, Fortify will redirect the user to the URI configured via the `home` configuration option within your application's `fortify` configuration file. If the login request was an XHR request, a 204 HTTP response will be returned.
351
351
352
-
If the request was not successful, the user will be redirected back to the twofactor challenge screen and the validation errors will be available to you via the shared `$errors`[Blade template variable](/docs/{{version}}/validation#quick-displaying-the-validation-errors). Or, in the case of an XHR request, the validation errors will be returned with a 422 HTTP response.
352
+
If the request was not successful, the user will be redirected back to the two-factor challenge screen and the validation errors will be available to you via the shared `$errors`[Blade template variable](/docs/{{version}}/validation#quick-displaying-the-validation-errors). Or, in the case of an XHR request, the validation errors will be returned with a 422 HTTP response.
353
353
354
354
<aname="disabling-two-factor-authentication"></a>
355
-
### Disabling TwoFactor Authentication
355
+
### Disabling Two-Factor Authentication
356
356
357
-
To disable twofactor authentication, your application should make a DELETE request to the `/user/two-factor-authentication` endpoint. Remember, Fortify's twofactor authentication endpoints require [password confirmation](#password-confirmation) prior to being called.
357
+
To disable two-factor authentication, your application should make a DELETE request to the `/user/two-factor-authentication` endpoint. Remember, Fortify's two-factor authentication endpoints require [password confirmation](#password-confirmation) prior to being called.
You may customize the behavior of the underlying queued job by defining properties on your notification class. These properties will be inherited by the queued job that sends the notification:
282
+
283
+
```php
284
+
<?php
285
+
286
+
namespace App\Notifications;
287
+
288
+
use Illuminate\Bus\Queueable;
289
+
use Illuminate\Contracts\Queue\ShouldQueue;
290
+
use Illuminate\Notifications\Notification;
291
+
292
+
class InvoicePaid extends Notification implements ShouldQueue
293
+
{
294
+
use Queueable;
295
+
296
+
/**
297
+
* The number of times the notification may be attempted.
298
+
*
299
+
* @var int
300
+
*/
301
+
public $tries = 5;
302
+
303
+
/**
304
+
* The number of seconds the notification can run before timing out.
305
+
*
306
+
* @var int
307
+
*/
308
+
public $timeout = 120;
309
+
310
+
/**
311
+
* The maximum number of unhandled exceptions to allow before failing.
312
+
*
313
+
* @var int
314
+
*/
315
+
public $maxExceptions = 3;
316
+
317
+
// ...
318
+
}
319
+
```
320
+
321
+
If you would like to ensure the privacy and integrity of a queued notification's data via [encryption](/docs/{{version}}/encryption), add the `ShouldBeEncrypted` interface to your notification class:
322
+
323
+
```php
324
+
<?php
325
+
326
+
namespace App\Notifications;
327
+
328
+
use Illuminate\Bus\Queueable;
329
+
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
330
+
use Illuminate\Contracts\Queue\ShouldQueue;
331
+
use Illuminate\Notifications\Notification;
332
+
333
+
class InvoicePaid extends Notification implements ShouldQueue, ShouldBeEncrypted
334
+
{
335
+
use Queueable;
336
+
337
+
// ...
338
+
}
339
+
```
340
+
341
+
In addition to defining these properties directly on your notification class, you may also define `backoff` and `retryUntil` methods to specify the backoff strategy and retry timeout for the queued notification job:
342
+
343
+
```php
344
+
use DateTime;
345
+
346
+
/**
347
+
* Calculate the number of seconds to wait before retrying the notification.
348
+
*/
349
+
public function backoff(): int
350
+
{
351
+
return 3;
352
+
}
353
+
354
+
/**
355
+
* Determine the time at which the notification should timeout.
356
+
*/
357
+
public function retryUntil(): DateTime
358
+
{
359
+
return now()->addMinutes(5);
360
+
}
361
+
```
362
+
363
+
> [!NOTE]
364
+
> For more information on these job properties and methods, please review the documentation on [queued jobs](/docs/{{version}}/queues#max-job-attempts-and-timeout).
0 commit comments