Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thusfar's avatar

How to validate provided country code?

Spark has built in CountryValidator which is basically just a class.

I'm wondering how can I use that custom validator with Validator::make??

0 likes
1 reply
bobbybouwmann's avatar
Level 88

I don't have the spark code in front of me, but spark should register this validator in one of the service providers. The CountryValidator class probably has a function looking like this

public function validateCountry($attribute, $value, $parameters);

The basic rule for this is that anything that comes after validate is the syntax of the rule as well. So for the above example the rule looks like this

$rules = [
    'country' => 'required|country',
];

I hope this helps you to find the correct class so you can reuse the validation method ;)

1 like

Please or to participate in this conversation.