- How do I install ofcold/identity-card in a Laravel app?
- Run composer require ofcold/identity-card. Laravel auto-discovers the service provider, and you can optionally publish the config with php artisan vendor:publish. There is no database, queue, cache, or network setup involved, so most of the work is just the Composer step plus using the validation rule where you need it.
- Which PHP and Laravel versions does ofcold/identity-card support?
- There is no published support matrix, and the last release was July 2023, so PHP 8.3/8.4 and Laravel 11/12 are not officially confirmed. The library is small and dependency-free, so it usually still works, but pin a version and run your own tests on the framework version you deploy. Provider auto-discovery and the facade are stable Laravel APIs; the validation rule's contract with the validator is the part most likely to drift across majors.
- How do I use the identity card validation rule in a FormRequest?
- Add the package's rule class to the rules array for your ID field, alongside required and string. Failures surface as standard Laravel validation errors, so it slots into existing form and API validation flows without custom plumbing. Keep the raw value out of error messages and logs, since it is sensitive personal information.
- Does ofcold/identity-card prove that a Chinese ID number is authentic?
- No. It checks internal consistency only: 18-digit format, checksum, plausible birth date, and a region code that exists in its static table, which is not the same as proving the document is genuine. A well-formed counterfeit will pass. Real identity verification requires a government or NCIIC-backed two-factor check, so describe the capability as format validation in your product to avoid overpromising.
- How do I get birth date, gender, age, and region from a Chinese ID number?
- Parse the string with the package parser and read the derived attributes. The birth date comes from digits 7 through 14, gender from the 17th digit (odd is male, even is female), and the first six digits map to an administrative region code. Age is computed from the birth date, and the package also exposes zodiac and constellation. Wrap the call in your own IdentityCardParser interface so you can swap implementations later.
- Can I generate fake Chinese ID numbers for tests and database seeding?
- Yes, the package includes a generator that produces checksum-valid 18-digit numbers, which is exactly what you want for factories, seeders, and fixtures. Keep it out of production code paths: generated IDs pass every downstream check by construction, so accidental exposure can create records that look legitimate.
- How current is the region code table, and can valid IDs be rejected?
- Region checks rely on a static GB/T 2260 administrative division table shipped with the package, and the last release was July 2023. Chinese county-level divisions are merged and renumbered regularly, so IDs issued or renumbered after that snapshot can fail validation, producing false negatives that reject real users. Treat region lookup as advisory, log failures, and plan to refresh or fork the table.
- Can I use ofcold/identity-card without Laravel, in plain PHP?
- Yes. It is a dependency-free, I/O-free PHP library that validates and parses a string, so the core classes work in any Composer project. The service provider, facade, and validation rule are Laravel conveniences layered on top. In a non-Laravel app you just instantiate the parser or generator directly.
- What license is ofcold/identity-card released under, and can I use it commercially?
- GitHub reports the license as NOASSERTION, meaning no standard license file was detected, so there is no explicit grant to use, modify, or redistribute the code. That is a blocking item for commercial use until legal review or the maintainer adds a LICENSE file. Raise it before procurement or security review rather than after.
- Is it safe to store or log Chinese ID numbers parsed with this package?
- The package only validates and parses; it does nothing for encryption, retention, redaction, or access control. Chinese resident ID numbers are sensitive personal information under PIPL, and the derived birth date, gender, and domicile form a strong quasi-identifier set. Store raw values encrypted, avoid logging them or their derived fields, and define a retention policy in your application layer.