. */ namespace App\Console\Commands\Accounts; use Illuminate\Console\Command; use Carbon\Carbon; use App\Account; class ClearUnconfirmed extends Command { protected $signature = 'accounts:clear-unconfirmed {days} {--apply} {--and-confirmed}'; protected $description = 'Clear unconfirmed accounts after n days'; public function handle() { $accounts = Account::where( 'created_at', '<', Carbon::now()->subDays($this->argument('days'))->toDateTimeString() ); if (!$this->option('and-confirmed')) { $accounts = $accounts->where('activated', false); } $count = $accounts->count(); if ($this->option('apply')) { $this->info($count . ' accounts in deletion…'); $accounts->delete(); $this->info($count . ' accounts deleted'); return Command::SUCCESS; } $this->info($count . ' accounts to delete'); return Command::SUCCESS; } }