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

das-cert's avatar

Custom validation on combined fields

So, I read the documentation and reviewed some web sites regarding custom validation and I got it to work for me (mods to AppServiceProvider etc) when I call the validation from my simple test. The problem is this:

In real life have two fields on screen, countrycode and phonenumber and I need to validate them as a single unit i.e. "+".$countrycode.$phonenumber with a call to Twilio.

What is the correct way to achieve the desired result? Code before or after Spark::validateUsersWith ? or can I pass more than one field to a custom validation? I couldn't find any relevant documentation on parameter passing in a custom validation.

BTW, very, VERY new to Laravel and Spark so don't jump too hard.

Thanks in advance

David

0 likes
3 replies
bashy's avatar

Why do you need to validate them together? Can't you work out if they're valid on their own?

What rules are you using?

das-cert's avatar

@bashy Why do I need to validate them together? Because one can't validate them successfully separately. While some people might be happy to just check the number of digits and so forth, I want to use the validation routine provided by the Twilio API which tells me all sorts of things about the number that has been entered - such as whether it's a real phone number, including carrier.

bashy's avatar

Ah I missed the "with a call to Twilio". Sounds like Spark is quite different to default Laravel so not having used it, I can't really say.

You can normally access formdata in FormRequests via $this->input('field_name') but you're not using one, or it doesn't.

Please or to participate in this conversation.