feat: clean devices tokens and sanctum expiration

This commit is contained in:
2026-05-21 21:53:13 +02:00
parent 55215b2c36
commit 417a1bc53c
5 changed files with 97 additions and 3 deletions
@@ -0,0 +1,35 @@
<?php
namespace App\Console\Commands;
use App\Models\DeviceToken;
use Illuminate\Console\Command;
class PruneStaleDeviceTokens extends Command
{
protected $signature = 'device-tokens:prune-stale
{--days=180 : Number of days to retain device tokens since last refresh}';
protected $description = 'Prune stale Expo push device tokens.';
public function handle(): int
{
$days = filter_var($this->option('days'), FILTER_VALIDATE_INT, [
'options' => ['min_range' => 1],
]);
if ($days === false) {
$this->error('The --days option must be an integer greater than zero.');
return self::FAILURE;
}
$deleted = DeviceToken::query()
->where('updated_at', '<', now()->subDays($days))
->delete();
$this->info("{$deleted} stale device token(s) pruned.");
return self::SUCCESS;
}
}