Laravel

How to Generate barcode in Laravel 8

In this article I will show you how we can generate barcode in Laravel 8.We will generate barcode using picqer/php-barcode-generator.

picqer/php-barcode-generator is a composer package for generating barcodes in your laravel 8 application. you can simply generate SVG, png, jpg, and HTML images of the barcode.

Let’s know something about barcode

A barcode or bar code is a method of representing data in a visual, machine-readable form. Initially, barcodes represented data by varying the widths and spacings of parallel lines.

If you want to know more about barcode, You can visit here.

To implement barcode generator we will follow the below steps:

  • Install Laravel
  • Install-Package Via Composer
  • Create Route
  • Create Blade File

Step – 1 Install Laravel project to begin your journey with Barcode Generator in Laravel 8.

composer create-project --prefer-dist laravel/laravel barcode-generator

Step – 2 Install package via composer

Now we have to install picqer/php-barcode-generator via composer, open your terminal and write the below command.

composer require picqer/php-barcode-generator

Step -3 Create Route

In this step, we will create one route for testing example. So, let’s add a new route to that file.

go to routes/web.php and add the below code.

Route::view('barcode', 'barcode');

Step – 4 Create Blade File

now we need to create barcode.blade.php to display bar code. so let’s create a blade file like the below code.

go to resources/view/barcode.blade.php.

<!DOCTYPE html>
<html>
<head>
    <title>How to Generate Bar Code in Laravel? - codehunger.in</title>
</head>
<body>
  
<h1>How to Generate Bar Code in Laravel? - codehunger.in</h1>
   
<h3>Product: 0001245259636</h3>
@php
    $generator = new Picqer\Barcode\BarcodeGeneratorHTML();
@endphp
  
{!! $generator->getBarcode('0001245259636', $generator::TYPE_CODE_128) !!}
  
  
<h3>Product 2: 000005263635</h3>
@php
    $generatorPNG = new Picqer\Barcode\BarcodeGeneratorPNG();
@endphp
  
<img src="data:image/png;base64,{{ base64_encode($generatorPNG->getBarcode('000005263635', $generatorPNG::TYPE_CODE_128)) }}">

</body>
</html>

I hope you like the above article, please give me 5 stars if you like the article.

Shaiv Roy

Hy Myself shaiv roy, I am a passionate blogger and love to share ideas among people, I am having good experience with laravel, vue js, react, flutter and doing website and app development work from last 7 years.

Related Articles

2 Comments

  1. ErrorClass ‘Picqer\Barcode\BarcodeGeneratorHTML’ not found (View: C:\xampp\htdocs\barcode-generator\resources\views\barcode.blade.php)

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button