Package Data | |
---|---|
Maintainer Username: | vpratfr |
Maintainer Contact: | contact@vincentprat.info (Vincent Mimoun-Prat) |
Package Create Date: | 2018-05-08 |
Package Last Update: | 2024-04-17 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-22 15:05:02 |
Package Statistics | |
---|---|
Total Downloads: | 265,427 |
Monthly Downloads: | 7,841 |
Daily Downloads: | 50 |
Total Stars: | 107 |
Total Watchers: | 4 |
Total Forks: | 10 |
Total Open Issues: | 0 |
marvinlabs/laravel-luhn
is a laravel package providing various Laravel utilities to work with the
Luhn algorithm such as:
The Luhn algorithm is used widely to verify that numbers are valid: credit card numbers, SIREN company codes, etc.
You can install the package via composer:
composer require marvinlabs/laravel-luhn
If you are using Laravel 5.5, the service provider and facade will automatically be discovered.
On earlier versions, you need to do that manually. You must install the service provider:
// config/app.php
'providers' => [
...
MarvinLabs\Luhn\LuhnServiceProvider::class
];
And optionally register an alias for the facade.
// config/app.php
'aliases' => [
...
'Luhn' => MarvinLabs\Luhn\Facades\Luhn::class,
];
The package provides an implementation to the algorithm interface defined in \MarvinLabs\Luhn\Contracts\LuhnAlgorithm
.
The contract provides 3 public methods to:
A facade is provided to access the Luhn algorithm implementation.
Luhn::isValid('1234');
Luhn::computeCheckDigit('1234');
Luhn::computeCheckSum('1234');
You can get an implementation of the Luhn algorithm at any time using the Laravel container.
$luhn = app(\MarvinLabs\Luhn\Contracts\LuhnAlgorithm::class); // Using the interface
$luhn = app('luhn'); // This shortcut works too, up to you ;)
The package provides custom rules to validate a string.
$validator = Validator::make($data, [
'number1' => 'luhn', // Using shorthand notation
'number2' => new LuhnRule(), // Using custom rule class
]);
See the dedicated change log
The MIT License (MIT). Please see License File for more information.