-
app/Console/Commands/DeleteNonEmailVerifiedUsersCommand.php
Open in GitHubuse App\Models\User; use Illuminate\Console\Command; use Illuminate\Database\Eloquent\Builder; final class DeleteNonEmailVerifiedUsersCommand extends Command { protected $signature = 'delete:non-email-verified-users'; protected $description = 'Delete non-email verified users older than 24 hours.'; public function handle(): void { User::where('email_verified_at', null) ->where('updated_at', '<', now()->subDay()) ->whereDoesntHave('links', function (Builder $query): void { $query->where('created_at', '<', now()->subDay()); }) ->whereDoesntHave('questionsSent', function (Builder $query): void { $query->where('created_at', '<', now()->subDay()); }) ->whereDoesntHave('questionsReceived', function (Builder $query): void { $query->where('created_at', '<', now()->subDay()); }) ->get() ->each ->purge(); } }