fredbradley / laravel-rule-nhs-number
A Laravel Validator Rule for checking the validity of a NHS Number
Installs: 2 451
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^7.4||^8.0
- fredbradley/php-nhs-number: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- mockery/mockery: ^1.1
- orchestra/testbench: ~4
- phpunit/phpunit: ~9
- sempro/phpunit-pretty-print: ^1.0
- vimeo/psalm: ^3.12
README
This is a Custom Laravel Rule for validating an NHS Number.
The NHS Number validation logic is written by Liam and found in a separate package, if you'd like to use it without Laravel's dependencies.
Installation
Install the package using Composer:
composer require fredbradley/laravel-rule-nhs-number
Laravel's service provider discover will automatically configure the service provider for you.
Using the Validator
After installation, the validator will be available for use directly in your validation rules.
'field_name' => 'nhsnumber'
Within the context of a form controller it would like like this:
return Validator::make($data, [ 'name' => 'required|string|max:255', 'nhs_number' => 'required|string|nhsnumber' ]);
Using the Rule Object
NB: This is needed required to use with some form builders like Kris Forms
return Validator::make($data, [ 'name' => 'required|string|max:255', 'nhs_number' => [ 'required', 'string', new \FredBradley\NhsNumber\ValidateNhsNumber() ] ]);
Added bonus: Generators
Because we're using Liam's original code, I've added in a Generator
helper class. Use this in your projects to generate valid random NHS Numbers:
echo \FredBradley\NhsNumber\Generator::nhsNumber(); // '9278462608'
echo \FredBradley\NhsNumber\Generator::nhsNumber(3); // ['7448556886', '0372104223', '8416367035']
Contributing
At the moment the package is only available in English - due to the way the error message is displayed. If someone would like to contribute to make it translatable that would be nice of them.
👷 Credits
- Fred Bradley for the Laravel-ication of the validator
- Liam Hammett for the original package
- Peter Fisher for the original class
- All Contributors
♻️ License
The MIT License (MIT). Please see the license file for more information.