PHPackages                             mvdnbrk/gtin - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. mvdnbrk/gtin

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

mvdnbrk/gtin
============

GTIN / EAN / UPC Validation for Laravel

v2.8.0(4y ago)3148.6k↓40%71MITPHPPHP ^7.1 || ^8.0

Since May 21Pushed 2y ago1 watchersCompare

[ Source](https://github.com/mvdnbrk/gtin)[ Packagist](https://packagist.org/packages/mvdnbrk/gtin)[ Docs](https://github.com/mvdnbrk/gtin)[ GitHub Sponsors](https://github.com/mvdnbrk)[ RSS](/packages/mvdnbrk-gtin/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (31)Used By (1)

GTIN / EAN / UPC Validation for Laravel
=======================================

[](#gtin--ean--upc-validation-for-laravel)

[![PHP version](https://camo.githubusercontent.com/d79a2d8b88c1ce71b113a1973d1be248c52a289b3ae1113e72c7118d9a724775/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d76646e62726b2f6774696e3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/d79a2d8b88c1ce71b113a1973d1be248c52a289b3ae1113e72c7118d9a724775/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d76646e62726b2f6774696e3f7374796c653d666c61742d737175617265)[![Latest Version on Packagist](https://camo.githubusercontent.com/9e618cd4b9dbe7d4ef290eeab1377a6823fb54dc841408ed8fddbf745e643c94/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d76646e62726b2f6774696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mvdnbrk/gtin)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Tests](https://camo.githubusercontent.com/72e517267b3f8fdcf6e0e821236618a064ed28ba6e47461a00bfb9031db6cc48/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6d76646e62726b2f6774696e2f74657374732f6d61696e3f6c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/mvdnbrk/gtin/actions?query=workflow%3Atests)[![Code style](https://camo.githubusercontent.com/ce2b2c350e010400db83a2a6c911f07d593ebfc514fe96b0c2cdb1241b1c1aeb/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f39313938363132312f736869656c643f7374796c653d666c61742d737175617265266272616e63683d6d61696e)](https://github.styleci.io/repos/91986121)[![Total Downloads](https://camo.githubusercontent.com/15d605524ac038dd01d8a5e608450a2e1aa32de8e3f7f4336b4d95fed803d14c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d76646e62726b2f6774696e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mvdnbrk/gtin)

Extension for the Laravel validation class.

Installation
------------

[](#installation)

You can install the package via composer:

```
$ composer require mvdnbrk/gtin
```

Usage
-----

[](#usage)

Now you can use the `gtin` validation to validate a GTIN-8, GTIN-12, GTIN-13 or GTIN-14:

```
$this->validate($request, [
    'somefield' => 'gtin',
]);
```

### Specifying a custom error message

[](#specifying-a-custom-error-message)

You may publish the language files with the following `artisan` command:

```
php artisan vendor:publish --tag=gtin-lang
```

Now you can customize the error message in `resources/lang/vendor/gtin/{loale}/validation.php`.

Another option is to define the error message by adding your message to the `custom` array in the `resources/lang/{locale}/validation.php` language file.

```
'custom' => [
    'somefield' => [
        'gtin' => 'Please enter a valid GTIN!',
    ],
],
```

Or with a JSON file stored in `resources/lang/{locale}.json`

```
{
    "validation.custom.somefield.gtin": "Please enter a valid GTIN!"
}
```

Or you may pass custom messages as the third argument to the `Validator::make` method as described in the [Laravel documentation](https://laravel.com/docs/validation#custom-error-messages).

### Helper function

[](#helper-function)

This package exposes a `is_gtin()` helper function to quickly validate a GTIN.
It will return a `boolean` whether the given value is a valid GTIN or not:

```
is_gtin('1300000000000')    // returns true
is_gtin('1234567891234')    // returns false
```

### Migrations

[](#migrations)

This package contains a helper method to create a GTIN column in your database table:

```
Schema::table('products', function (Blueprint $table) {
    $table->gtin();
});
```

If you would like to customize the column name and/or length you may pass these as parameters:

```
$table->gtin('ean13', 13);
```

To drop the column you may use the `dropGtin` method:

```
Schema::table('products', function (Blueprint $table) {
    $table->dropGtin();

    // $table->dropGtin('ean13');
});
```

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Mark van den Broek](https://github.com/mvdnbrk)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 99.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~60 days

Recently: every ~183 days

Total

30

Last Release

1534d ago

Major Versions

1.0.6 → v2.0.02017-11-07

PHP version history (5 changes)1.0.0PHP ~5.6|~7.0

1.0.6PHP ~7.1

v2.0.1PHP &gt;=7.0

v2.1.0PHP ^7.1

v2.7.0PHP ^7.1 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/802681?v=4)[Mark van den Broek](/maintainers/mvdnbrk)[@mvdnbrk](https://github.com/mvdnbrk)

---

Top Contributors

[![mvdnbrk](https://avatars.githubusercontent.com/u/802681?v=4)](https://github.com/mvdnbrk "mvdnbrk (182 commits)")[![marcelhoogantink](https://avatars.githubusercontent.com/u/51886888?v=4)](https://github.com/marcelhoogantink "marcelhoogantink (1 commits)")

---

Tags

eangtinlaravelupcvalidationlaravelvalidatorvalidationeanupcgtings1

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mvdnbrk-gtin/health.svg)

```
[![Health](https://phpackages.com/badges/mvdnbrk-gtin/health.svg)](https://phpackages.com/packages/mvdnbrk-gtin)
```

###  Alternatives

[intervention/validation

Additional validation rules for the Laravel framework

6826.7M8](/packages/intervention-validation)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M107](/packages/propaganistas-laravel-phone)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[laravel-validation-rules/credit-card

Validate credit card number, expiration date, cvc

2412.2M5](/packages/laravel-validation-rules-credit-card)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)[sunspikes/clamav-validator

Custom Laravel 5 anti-virus validator for file uploads.

3651.8M3](/packages/sunspikes-clamav-validator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
