Raviya Technical
Published in

Raviya Technical

Laravel with Packages | How to Generate BarCode in Laravel?

In this tutorial, you will learn the laravel barcode generator example. We will use how to generate barcodes in laravel. you will learn how to save generated bar code in laravel. Here you will learn the laravel barcode tutorial. Here, Creating a basic example of picqer/php-barcode-generator laravel php.

You can easily generate barcodes in laravel 5, laravel 6, laravel 7, laravel 8, and laravel 9 versions.

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.

Here, I write examples step by step to generate bar code in your laravel admin panel. so let’s follow a few steps to get this example:

Preview:

Step 1: Install Laravel

In the first step, If you haven’t installed laravel in your system then you can run the below command and get a fresh Laravel project.

composer create-project --prefer-dist laravel/laravel blog

Step 2: Install picqer/php-barcode-generator Package

Now we require to install picqer/php-barcode-generator package for the barcode generator, that way we can use its method. So open your terminal and run the below command.

composer require picqer/php-barcode-generator

Step 3: Create Route

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

routes/web.php

<?phpRoute::view('barcode', 'barcode');

Step 4: Create a Blade file

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

resources/views/barcode.blade.php

<!DOCTYPE html>
<html>
<head>
<title>How to Generate Bar Code in Laravel? - raviyatechnical</title>
</head>
<body>

<h1>How to Generate Bar Code in Laravel? - raviyatechnical</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>

Now you can run and check it.

I hope it can help you…

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store