Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Luhn

Laravel Luhn Laravel Package

marvinlabs/laravel-luhn

A Laravel package that adds Luhn algorithm validation for credit card numbers, IMEI codes, and other checksum-verified identifiers. It provides a ready-to-use validation rule and helper methods for quick integration into forms, APIs, and custom validation workflows.

View on GitHub
Deep Wiki
Context7

Laravel utilities to ease validation and computation of credit cards, SIREN, etc.

Frequently asked questions about Laravel Luhn
How do I install marvinlabs/laravel-luhn in a Laravel application?
Install it with Composer by running composer require marvinlabs/laravel-luhn. Laravel's package auto-discovery registers the service provider, so manual registration is normally unnecessary. If the package ships a publishable config file, use php artisan vendor:publish with the tag documented in the README. After that the validation rule and helper methods are available immediately.
Which Laravel versions does laravel-luhn support?
The package is framework-coupled and its releases track Laravel's major versions, with version 1.0.14 adding Laravel 13 compatibility. Because that support shipped as a patch release, the package's major version number does not reliably signal compatibility breaks, so read the illuminate/* constraints in composer.json before upgrading. Running composer why-not marvinlabs/laravel-luhn shows exactly which Laravel versions your lock file allows. If you are pinned to an older release, confirm whether Laravel 11 and 12 remain supported.
How do I validate a credit card number with the Luhn rule in Laravel?
The package registers a validation rule you can drop into a rules array or a FormRequest, typically alongside required and a digit-length check. Since Luhn only verifies the checksum, pair it with rules enforcing the expected length for the card brand, such as 16 digits for Visa or Mastercard. Always follow up with a real payment gateway authorization before treating a number as valid.
Does passing a Luhn check mean the credit card number is real?
No. The Luhn algorithm only confirms that the digits are internally consistent with a checksum, which catches typos and transposed digits. A number can pass Luhn and still be fabricated, closed, or belong to a different brand than expected. Treat it as a cheap sanity filter on the client and server, never as proof of a live account.
Can I use laravel-luhn outside validation rules, like in a controller or API?
Yes. The package exposes helper methods you can call directly from controllers, jobs, or API resources when you need a boolean checksum result without building a validator instance. This is handy for pre-flight checks in import jobs or for normalizing input before it reaches a payment service. Wrapping the call in your own service class keeps the dependency at the edge of your domain code.
Does this package validate IMEI numbers and SIREN numbers too?
Yes. Luhn applies to any numeric identifier that carries a check digit, and the package is documented for credit cards, IMEI codes, and SIREN numbers among others. The same rule and helper methods work for all of them because the underlying algorithm is identical. Just remember to enforce each identifier's length and prefix rules separately.
Is laravel-luhn safe to run in production, and does it make external calls?
Validation is pure PHP computation with no network calls, no external services, and no native extensions, so it is safe in request handlers and queue workers. The package does not store or transmit the values you validate. Keep in mind that card numbers are sensitive under PCI DSS, so avoid logging them even when validation fails.
How do I test code that uses the Luhn validation rule?
Test it like any Laravel validation rule: use Validator::make with representative passing and failing inputs, or assert the FormRequest's errors in a feature test. Cover the edge cases you care about, such as leading zeros, values containing spaces or dashes, letters, and wrong-length input. Check how the rule handles non-digit characters and add sanitization if your forms allow them, and note there is no external dependency to mock.
How do I customize the error message for the Luhn validation rule?
Pass a custom message for the rule in your FormRequest's messages method or in your validation language files, exactly as you would for a built-in rule. That lets you return a user-friendly message such as The card number is invalid instead of a technical checksum error. For multi-language apps, add the rule's key to each locale file.
Is marvinlabs/laravel-luhn actively maintained, and are there alternatives?
It is a small, single-purpose utility maintained by one author, and its release cadence is driven by Laravel major versions rather than feature work. That is acceptable for a checksum helper, but pin your constraint deliberately and watch for compatibility releases, since they ship at patch level. If you would rather not carry the dependency, Luhn is roughly twenty lines of PHP to implement yourself, with the tradeoff of owning the tests.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
vento/laravel-airbrake
wfeller/laravel-batch
maco-studios/mage-os-installer
busarm/armie
siberfx/laravel-logger
kfteam1991/dcat-admin
dashed/dashed-laposta
dashed/dashed-ecommerce-montaportal
dashed/dashed-ecommerce-etsy
neohq/string-blade-compiler
log1x/acf-composer
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core
nodisrupt/laravel-agent
sierratecnologia/media-manager