twofas/validation-rules
A Laravel package from TwoFAS that provides ready-made validation rules for two-factor authentication flows, making it easy to validate user input such as verification codes cleanly in form requests, controllers, and custom validators.
composer require twofas/validation-rules
vendor/twofas/validation-rules/composer.json and look at the extra.laravel.providers block. If a service provider is registered, it will boot automatically; if not, add it manually to config/app.php. Also check for a config/ directory inside the package — if one exists, publish it:
php artisan vendor:publish --provider="TwoFAS\\ValidationRules\\ValidationRulesServiceProvider"
src/ first. Most packages of this shape ship one class per rule, each implementing Illuminate\Contracts\Validation\Rule (or the newer ValidationRule on Laravel 10+). The namespace is usually TwoFAS\ValidationRules\Rules\*. Read the class docblocks — they define the expected input shape (phone number, TOTP code, base32 secret, etc.).FormRequest for a 2FA-related field:
use TwoFAS\ValidationRules\Rules\PhoneNumber;
public function rules(): array
{
return [
'phone' => ['required', 'string', new PhoneNumber()],
];
}
Confirm the exact class name from src/ — the namespace is the one thing you should never guess on a low-traffic package.required or nullable and usually string:
'code' => ['required', 'string', 'size:6', new TotpCode()],
namespace App\Rules;
class TwoFactorCode extends \TwoFAS\ValidationRules\Rules\TotpCode {}
Now a future swap is a one-file change instead of a grep across form requests.$v = Validator::make(['phone' => '+15551234567'], ['phone' => [new PhoneNumber()]]);
$this->assertTrue($v->passes());
Add failing cases (empty, whitespace, letters, wrong length) — this is where these rules earn their keep.resources/lang/, override messages per-locale rather than editing vendor files. If it does not, wrap the rule and return your own $fail() message.rules() or via the container — no state should live on the rule.composer.json ("twofas/validation-rules": "1.2.*") and audit src/ before upgrading. There will be no community answers on Stack Overflow.Rule contract was deprecated in favor of ValidationRule around Laravel 10. If the package targets an older Laravel, composer update on your app can silently break it. Check the illuminate/support constraint in the package's composer.json.true on '' or null because Laravel's implicit validation doesn't apply. Combine with required explicitly — do not assume the rule implies presence.giggsey/libphonenumber-for-php transitively. If you see Class 'libphonenumber\PhoneNumberUtil' not found, the package's require block missed it — add it yourself and file upstream./^[A-Z2-7]+$/-style patterns; the u modifier and \A...\z anchors matter. Test with non-ASCII input to confirm behaviour.dump()s the value and returns true/false to confirm the rule is even being invoked — Laravel silently skips rules on missing attributes and on nullable + null.Validator::extend() macros (e.g., 'twofas_phone'), use the string form instead of new Rule(). String macros fail loudly with a clear "no such rule" exception, which is easier to debug than a class that never fires.message() method. If neither exists, subclass and override the $fail message — don't monkey-patch vendor files.How can I help you explore Laravel packages today?