DNS for Laravel
Validation rules
Validation rules
Both rules implement Laravel's ValidationRule contract and resolve the
container-bound Cbox\Dns\Dns, so they honour your configured transport and can
be faked in tests.
DnsRecordExists
Passes when the value (a hostname) resolves at least one record of the given
type. Defaults to A.
use Cbox\LaravelDns\Rules\DnsRecordExists;
use Cbox\Dns\Enums\RecordType;
$request->validate([
'mail_domain' => ['required', new DnsRecordExists(RecordType::MX)],
'apex' => ['required', new DnsRecordExists()], // A record
]);
Fails when the name has no record of the type, or the lookup fails.
DomainVerified
Passes only when the value (a domain) publishes the expected challenge token in its authoritative TXT record — a "prove you own this domain" field. Because the token is read from the zone's own nameservers, a pass is a genuine ownership proof, not a cached view.
use Cbox\LaravelDns\Rules\DomainVerified;
$request->validate([
'domain' => ['required', new DomainVerified($team->dns_token)],
]);
The challenge host the user must publish is derived from the
dns.challenge_prefix config key (default _cbox-challenge.<domain>).