<?php

namespace App\Console\Commands;

use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class ClearPasswordToken extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'clear:password_tokens';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        // Calculate the time 1 hour ago
        $oneHourAgo = Carbon::now()->subHour();

        // Retrieve records created 1 hour ago or later using DB builder
        $records = DB::table('password_reset_tokens')
            ->where('created_at', '<=', $oneHourAgo)
            ->delete();
    }
}
