Laravel Integration
slashlab/numerik-laravel adds Numerik’s validators as Laravel validation rules. It supports both class-based and string-based syntax and is auto-discovered — no manual registration needed.
Requirements
Section titled “Requirements”- PHP 8.3 or higher
- Laravel 11, 12, or 13
Installation
Section titled “Installation”-
Require the package
Terminal window composer require slashlab/numerik-laravel -
No configuration needed
The service provider is auto-discovered. There is no config file to publish or boot step to add.
use SlashLab\NumerikLaravel\Rules\PeselRule;use SlashLab\NumerikLaravel\Rules\NipRule;use SlashLab\NumerikLaravel\Rules\RegonRule;use SlashLab\NumerikLaravel\Rules\KrsRule;
public function rules(): array{ return [ 'pesel' => ['required', new PeselRule()], 'nip' => ['required', new NipRule()], 'regon' => ['required', new RegonRule()], 'krs' => ['required', new KrsRule()], ];}Use plain strings when you don’t need constructor options. The rules are registered under the lowercase identifier name.
public function rules(): array{ return [ 'pesel' => ['required', 'pesel'], 'nip' => ['required', 'nip'], 'regon' => ['required', 'regon'], 'krs' => ['required', 'krs'], ];}Validation messages
Section titled “Validation messages”Class-based rules return a distinct message for each failure reason. For example, a NIP with an incorrect checksum returns a different message than one with an invalid length.
Error messages resolve the field label from validation.attributes when available, matching the behaviour of Laravel’s built-in rules. If no label is registered, the field name is humanised — underscores replaced with spaces, first letter capitalised.
'attributes' => [ 'nip_number' => 'NIP',],The package ships with English (en) and Polish (pl) translations. To publish and customise them:
php artisan vendor:publish --tag=numerik-langThis copies the translation files to lang/vendor/numerik/. Edit the messages there to override any string.
Strict mode
Section titled “Strict mode”All rules accept an optional strict parameter (default true). In strict mode, additional semantic checks are applied on top of structural and checksum validation.
For PESEL, strict mode rejects numbers with a future birth date or all-identical digits:
// strict on (default) — rejects future dates and suspicious patternsnew PeselRule()
// strict off — only structural and checksum checks are appliednew PeselRule(strict: false)The same parameter is accepted by NipRule, RegonRule, and KrsRule.
PESEL constraints
Section titled “PESEL constraints”PeselRule supports additional constraints that are checked after the number passes structural validation.
Gender
Section titled “Gender”Reject numbers that do not match an expected gender:
use SlashLab\Numerik\Enums\Gender;
new PeselRule(gender: Gender::Male)new PeselRule(gender: Gender::Female)Birth date range
Section titled “Birth date range”Reject numbers whose encoded birth date falls outside a given range:
new PeselRule(bornBefore: new DateTimeImmutable('2000-01-01'))new PeselRule(bornAfter: new DateTimeImmutable('1980-12-31'))Constraints can be combined:
new PeselRule( gender: Gender::Female, bornAfter: new DateTimeImmutable('1990-01-01'), bornBefore: new DateTimeImmutable('2005-01-01'),)Source
Section titled “Source”- GitHub: github.com/Sqrcz/numerik-laravel
- Packagist: packagist.org/packages/slashlab/numerik-laravel