Files
UNIT3D/app/Console/Commands/AutoRecycleFailedLogins.php
2024-05-23 13:58:29 +00:00

58 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <hdinnovations@protonmail.com>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/
namespace App\Console\Commands;
use App\Models\FailedLoginAttempt;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Throwable;
class AutoRecycleFailedLogins extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'auto:recycle_failed_logins';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Recycle Failed Logins Once 30 Days Old.';
/**
* Execute the console command.
*
* @throws Exception|Throwable If there is an error during the execution of the command.
*/
final public function handle(): void
{
$current = Carbon::now();
$failedLogins = FailedLoginAttempt::where('created_at', '<', $current->copy()->subDays(30)->toDateTimeString())->get();
foreach ($failedLogins as $failedLogin) {
$failedLogin->delete();
}
$this->comment('Automated Purge Old Failed Logins Command Complete');
}
}