Luhn Algorithm Package for Laravel

Luhn Algorithm Package for Laravel

Laravel Luhn is a package by Vincent Prat that provides utilities to ease validation and computation of credit cards, SIREN codes, and other use-cases for the Luhn algorithm.

The Luhn algorithm (Wikipedia), developed in the 1950’s by IBM scientist Hans Peter Luhn, is a “simple checksum formula used to validate a variety of identification numbers.” Such numbers range from credit card numbers to various types of government identification numbers such as NPI numbers issued to health care providers.

Using the Laravel Luhn package, you can validate numbers using the package’s validation rule:


$validator = Validator::make($data, [
    'number1' => 'luhn', // Using shorthand notation
    'number2' => new LuhnRule(), // Using custom rule class

The Luhn algorithm implementation using the provided facade includes three methods, including isValid(), computeCheckDigit(), and computeCheckSum():



Check out marvinlabs/laravel-luhn on GitHub for complete installation and usage instructions. If you are interested in learning more about the Luhn algorithm, the Luhn algorithm page on Wikipedia has some good information, even including some code examples of how the algorithm works.

Filed in: Laravel Packages


Join 31,000+ others and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Software Developer
Remote (US & Canada)
😎 Laravel Developer
Jogg, Inc
Junior, Mid, and Senior Software Engineers. Laravel / Vue. Saint Petersburg, FL
Saint Petersburg, FL and Remote
Senior PHP Developer (Laravel)
The Interaction Design Foundation
Fullstack Laravel Engineer (Munich/Remote) 💻
Munich, Germany or Remote