- What is phpviet/validation used for in Laravel?
- phpviet/validation provides Vietnamese-specific validation rules for Laravel applications. It plugs into Laravel's native Validator so you can check locally relevant formats such as phone numbers, citizen identity numbers, tax codes, and other Vietnamese identifiers. It is useful when standard Laravel rules do not cover Vietnamese data formats or localized error messages.
- How do I install phpviet/validation with Composer?
- Install it as a Composer dependency in your Laravel project using the package name phpviet/validation. Run the Composer require command from your project root and follow the repository README for any service provider, configuration, or publishing steps. Because it integrates with Laravel's validator, you can then use its rules in validators, form requests, and API validation.
- Which Laravel versions does phpviet/validation support?
- The package is designed for Laravel's native Validator integration, but the exact supported Laravel versions are defined by the package's Composer constraints and README. Check the repository's composer.json and release notes before installing, especially if you are on an older Laravel version or a newly released major version. Composer will also warn you if your Laravel version does not satisfy the package requirements.
- What Vietnamese data formats can I validate with this package?
- The package focuses on common Vietnamese data formats, including phone numbers, citizen identity card numbers, tax codes, and other local identifiers. The exact rule names and format coverage should be confirmed in the README for your installed version. You can combine these rules with Laravel's built-in rules such as required, string, nullable, and unique.
- How do I use phpviet/validation rules in a Laravel Form Request?
- Use the package rules in your Form Request's rules method just like any other Laravel validation rule. Add the Vietnamese-specific rule to the relevant field and keep standard rules such as required or nullable alongside it. Then type-hint the Form Request in your controller and let Laravel handle validation and error responses as usual.
- Can I customize validation error messages and attribute names?
- Yes, the package supports customizable messages and attribute names. You can use Laravel's standard message and attribute customization approaches, such as defining messages and attributes in a Form Request or passing them directly to the validator. This lets you return clear Vietnamese or English error text that fits your application's tone.
- Does phpviet/validation work for API validation and JSON responses?
- Yes, because it integrates with Laravel's native Validator, it works wherever Laravel validation works, including API endpoints and JSON requests. When validation fails, Laravel can return its standard JSON error response with the package's messages. You can also customize the response format in your Form Request or exception handler.
- How do I test Vietnamese phone or citizen ID validation in Laravel?
- Test the rules the same way you test other Laravel validation rules: create validator instances or send requests through Form Requests and assert that valid samples pass while invalid samples fail. Include edge cases such as missing leading zeros, wrong lengths, non-numeric characters, and empty values. Keep representative Vietnamese phone and citizen ID samples in your test fixtures so regressions are easy to spot.
- Is phpviet/validation suitable for production and actively maintained?
- The package is lightweight and installable via Composer, making it practical for production Laravel applications that need Vietnamese-specific validation. Before relying on it, review the GitHub repository and Packagist page for recent releases, open issues, and compatibility with your Laravel version. Pin a known-good version in Composer and add tests for the Vietnamese formats your application depends on.
- What are alternatives to phpviet/validation for Vietnamese validation in Laravel?
- Alternatives include writing custom Laravel validation rules with regular expressions, using built-in rules such as regex and digits, or adopting another country-specific validation package. Custom rules give maximum control but require you to maintain format logic and test cases yourself. phpviet/validation is convenient when you want ready-to-use Vietnamese identifier rules and localized messages without building them from scratch.