option('apply'); // Candidati: unità che non hanno né codice né interno valorizzato $query = UnitaImmobiliare::where(function ($q) { $q->whereNull('codice_unita') ->orWhereIn('codice_unita', ['0', '', '0 ', ' 0', '0.0']) ->orWhere('codice_unita', 'like', '%-0'); })->where(function ($q) { $q->whereNull('interno') ->orWhereIn('interno', ['0', 0, '', '0 ', ' 0']); })->whereNotIn('tipo_unita', [ 'cantina', 'box', 'garage', 'magazzino', 'deposito', 'posto_auto', ]); $count = $query->count(); if ($count === 0) { $this->info('Nessuna unità con codice_unita nullo/0 trovata.'); return 0; } $this->info(($apply ? 'Cancellazione' : 'Report') . " su {$count} unità."); if (!$apply) { return 0; } $query->chunkById(200, function ($chunk) { foreach ($chunk as $unit) { $unit->delete(); } }); $this->info('Cancellazione completata (soft delete).'); return 0; } }