Skip to content

Commit 768cdd1

Browse files
[10.x] Independent token expiration (#9236)
* Add independent token expiration to sanctum.md * Update sanctum.md --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent f053c49 commit 768cdd1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

sanctum.md

+8
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,14 @@ By default, Sanctum tokens never expire and may only be invalidated by [revoking
237237
'expiration' => 525600,
238238
```
239239

240+
If you would like to specify the expiration time of each token independently, you may do so by providing the expiration time as the third argument to the `createToken` method:
241+
242+
```php
243+
return $user->createToken(
244+
'token-name', ['*'], now()->addWeek()
245+
)->plainTextToken;
246+
```
247+
240248
If you have configured a token expiration time for your application, you may also wish to [schedule a task](/docs/{{version}}/scheduling) to prune your application's expired tokens. Thankfully, Sanctum includes a `sanctum:prune-expired` Artisan command that you may use to accomplish this. For example, you may configure a scheduled tasks to delete all expired token database records that have been expired for at least 24 hours:
241249

242250
```php

0 commit comments

Comments
 (0)