Add a CLI command to remove expired tokens

This commit is contained in:
Daniel_I_Am 2021-09-02 13:07:48 +02:00
parent 18d054edf0
commit 55e91a323c

View File

@ -0,0 +1,48 @@
<?php
namespace App\Console\Commands;
use App\Models\AuthenticationToken;
use Carbon\Carbon;
use Illuminate\Console\Command;
class ClearExpiredAuthenticationCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'auth:clear-tokens';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Clear all expired authentication tokens';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
AuthenticationToken::select()
->whereDate('valid_until', '<', Carbon::now())
->delete();
return 0;
}
}