Laravel 5/6/7/8 Barcode Generator - Effortless and Dynamic

 How to Generator Dynamic Barcode in Laravel 5/6/7/8 using milon/barcode Package

Laravel-5/6/7/8-Barcode-Generator-Effortless-and-Dynamic

In this article we will learn how to generate barcode in Laravel using milon/barcode package . You can use this package in any of your Laravel version like Laravel 5,6,7,8 . In this article i will show you the example in Laravel 8 project . milon/barcode package provides lots of barcode generator like Qr Code, PDF417, C39, C39+, C39E, C39E+, C93, S25, S25+, I25, I25+, C128, C128A, C128B, C128C, 2-Digits UPC-Based Extention, 5-Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI etc .

Just follow the steps one by one it super easy to use barcode generator on your Laravel project , so let's see how to use Barcode Generator in Laravel .

Table of Content :-

  • Install a Laravel Project
  • Install milon/barcode Package
  • Publish milon/barcode package
  • Setup Route , Controller and View
  • Output

Step 1 - Install a Laravel Project :-

The very first step that we need to do is to install a fresh Laravel project , if you have already installed then you can skip this step . You can use the following command to install a fresh Laravel project .

composer create-project laravel/laravel example-app

Step 2 - Install milon/barcode Package :-

Now we have to install milon/barcode package , use the following command to install this package on your laravel project .

composer require milon/barcode

Step 3 - Publish milon/barcode package :-

After successfull installation of package we have to publish this package in our config/app.php file . So make this following changes in your config/app.php file .

Open config/app.php file and a new item in providers array as shown below .

'providers' => 
     [
       .................. ,
       .................. ,
       .................. ,
       .................. ,
       Milon\Barcode\BarcodeServiceProvider::class,
     ]

Open config/app.php and a new item in aliases array as shown below .

'aliases' => 
     [
       .................. ,
       .................. ,
       .................. ,
       .................. ,
       'DNS1D' => Milon\Barcode\Facades\DNS1DFacade::class,
       'DNS2D' => Milon\Barcode\Facades\DNS2DFacade::class,
     ]

Step 4 - Setup Route , Controller and View :-

Setup your route controller and view file , Below code is the sample that how i setup my route, controller and view file .

web.php :-

Route::get('/barcode', [barcodeController::class, 'GenerateBarcode']);

barcodeController.php :-

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class barcodeController extends Controller
{
    public function GenerateBarcode()
    {
    	return view('barcode');
    }
}

barcode.blade.php :-

<!DOCTYPE html>
<html>
<head>
	<title>Barcode Generator</title>
	<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.1/dist/umd/popper.min.js" integrity="sha384-SR1sx49pcuLnqZUnnPwx6FCym0wLsk5JZuNx2bPPENzswTNFaQU1RDvt3wT4gWFG" crossorigin="anonymous"></script>
	<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.min.js" integrity="sha384-j0CNLUeiqtyaRmlzUHCPZ+Gy5fQu0dQ6eZ/xAww941Ai1SxSY+0EQqNXNE6DZiVc" crossorigin="anonymous"></script>
	<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
</head>
<body>
	<div class="row my-4">
		<div class="col-12 text-center">
			<h2>Laravel 8 Barcode Generator</h2>
		</div>
	</div>
	<div class="row">
		<div class="col-2"></div>
		<div class="col-2">
			<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('4445645656', 'S25')}}" alt="barcode" />		
		</div>
		<div class="col-2">
			<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('4445645656', 'C128')}}" alt="barcode" />		
		</div>
		<div class="col-2">
			<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('4445645656', 'C128A')}}" alt="barcode" />		
		</div>
		<div class="col-2">
			<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('4445645656', 'C39')}}" alt="barcode" />		
		</div>
		<div class="col-2"></div>
	</div>

	<div class="row my-2">
		<div class="col-2"></div>
		<div class="col-2">
			<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('4445645656', 'MSI+')}}" alt="barcode" />		
		</div>
		<div class="col-2">
			<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('4445645656', 'POSTNET')}}" alt="barcode" />		
		</div>
		<div class="col-2">
			<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('4445645656', 'PLANET')}}" alt="barcode" />		
		</div>
		<div class="col-2">
			<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('4445645656', 'RMS4CC')}}" alt="barcode" />		
		</div>
		<div class="col-2"></div>
	</div>


</body>
</html>

In this example i have only used 8 barcodes in my view file but there are lots of other barcodes available you can use that are shown below .

 DNS1D::getBarcodePNG('4445645656', 'C39');
 DNS1D::getBarcodePNG('4445645656', 'C39+');
 DNS1D::getBarcodePNG('4445645656', 'C39E');
 DNS1D::getBarcodePNG('4445645656', 'C39E+');
 DNS1D::getBarcodePNG('4445645656', 'C93');
 DNS1D::getBarcodePNG('4445645656', 'S25');
 DNS1D::getBarcodePNG('4445645656', 'S25+');
 DNS1D::getBarcodePNG('4445645656', 'I25');
 DNS1D::getBarcodePNG('4445645656', 'I25+');
 DNS1D::getBarcodePNG('4445645656', 'C128');
 DNS1D::getBarcodePNG('4445645656', 'C128A');
 DNS1D::getBarcodePNG('4445645656', 'C128B');
 DNS1D::getBarcodePNG('4445645656', 'C128C');
 DNS1D::getBarcodePNG('44455656', 'EAN2');
 DNS1D::getBarcodePNG('4445656', 'EAN5');
 DNS1D::getBarcodePNG('4445', 'EAN8');
 DNS1D::getBarcodePNG('4445', 'EAN13');
 DNS1D::getBarcodePNG('4445645656', 'UPCA');
 DNS1D::getBarcodePNG('4445645656', 'UPCE');
 DNS1D::getBarcodePNG('4445645656', 'MSI');
 DNS1D::getBarcodePNG('4445645656', 'MSI+');
 DNS1D::getBarcodePNG('4445645656', 'POSTNET');
 DNS1D::getBarcodePNG('4445645656', 'PLANET');
 DNS1D::getBarcodePNG('4445645656', 'RMS4CC');
 DNS1D::getBarcodePNG('4445645656', 'KIX');
 DNS1D::getBarcodePNG('4445645656', 'IMB');
 DNS1D::getBarcodePNG('4445645656', 'CODABAR');
 DNS1D::getBarcodePNG('4445645656', 'CODE11');
 DNS1D::getBarcodePNG('4445645656', 'PHARMA');
 DNS1D::getBarcodePNG('4445645656', 'PHARMA2T');

You can also visit the official github site of milon/barcode to get more information and to get more barcodes as it provides lots of super cool barcodes like colored barcodes , 1D barcode and 2D barcodes etc .


Previous Post Next Post

Contact Form