max13/laravel-barcode

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Laravel package to manage and generate barcodes

v0.3.2 2021-02-14 20:04 UTC

This package is auto-updated.

Last update: 2021-10-14 21:55:39 UTC


README

Latest Version on Packagist GitHub Tests Action Status Total Downloads

With this package you can manage barcodes (external barcodes, checkings, etc…) or generate your own as long as you configure it correctly.

Installation

You can install the package via composer:

composer require max13/laravel-barcode

This package embeds corresponding fonts to write the barcode on a webpage. You will see how to use them in the Usage section below.

Configuration

Barcode types are available like so (defaults to ean13):

type has font
ean8 yes
ean13 yes

To change the barcode type used, set to your .env file: BARCODE_TYPE= with the barcode type you want to use.

When a barcode has a font and you would use it, you need to publish the package assets using:

php artisan vendor:publish --provider="Max13\Barcode\ServiceProvider" --tag=public

Don’t forget to include the css files in your layouts.

If you need to see or change this package config file, you can publish the config file using this command:

php artisan vendor:publish --provider="Max13\Barcode\ServiceProvider" --tag=config

This will export the config file to your app’s config folder.

Usage

// To check an ean13 barcode:
if (Barcode::isValid('0123456789104')) {
    // This barcode is valid
}

// To calculate an ean13 barcode check digit (the last digit)
echo Barcode::checksum('012345678910'); // Show: '4'

// To fix an ean13 barcode if it's needed
echo Barcode::fix('0123456789100'); // Show: '0123456789104'

And finally, if you need to write the barcode using the embedded font, you need to get the encoded form of the barcode (ex: in case of ean13, the font will be applied on html class f-ean13):

<span class="f-ean13">{{ Barcode::encode('0123456789104') }}</span>

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.