$ids every id in the delete request */ public function __construct(private readonly array $ids) {} public function validate(string $attribute, mixed $value, Closure $fail): void { $batch = array_map('intval', array_filter($this->ids, 'is_numeric')); $orphaned = Invoice::where('related_invoice_id', (int) $value) ->where('type', Invoice::TYPE_CREDIT_NOTE) ->whereNotIn('id', $batch) ->exists(); if ($orphaned) { $fail('Credit note exists.'); } } }