Skip to content

Commit 34e5687

Browse files
committed
feat: added scheduled command to clean LoginTokens table automatically
1 parent f822726 commit 34e5687

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Models\LoginToken;
6+
use Illuminate\Console\Command;
7+
8+
class CleanLoginTokensTable extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'system:clean-login-tokens-table';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Clean Login Tokens table to improve overall performance';
23+
24+
/**
25+
* Execute the console command.
26+
*/
27+
public function handle()
28+
{
29+
// remove old stale tokens
30+
LoginToken::where('created_at', '<', now()->subWeeks(1))
31+
->delete();
32+
33+
// remove consumed tokens.
34+
// For analytics sake, we can maybe only rely on the first
35+
// option. We can track how often users use the magic link
36+
}
37+
}

app/Console/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Kernel extends ConsoleKernel
1313
protected function schedule(Schedule $schedule): void
1414
{
1515
$schedule->command('sitemap:generate')->daily();
16+
$schedule->command('system:clean-login-tokens-table')->daily();
1617
}
1718

1819
/**

0 commit comments

Comments
 (0)