Laravel - Barcode generator example using milon/barcode

By Hardik Savani | May 17, 2016 | Category : Laravel

In this post i am going to give you example of how to generate barcode in laravel application. we will create barcode using milon/barcode package that provide several way to generate QR Code and barcode. If you need to generate barcode for your products then you generate barcode sticker in laravel application using milon/barcode package. I added preview of barcode after finish example you can find output like bellow preview. It's provide several barcode like Qr Code, PDF417, C39,C39+, C39E,C39E+, C93, S25,S25+, I25,I25+ etc. You have to just follow few step:


Step 1: Installation

In first step we will install milon/barcode package for generate bar-code image. so first fire bellow command in your cmd or terminal:

composer require milon/barcode

Now we need to add provider path and alias path in config/app.php file so open that file and add bellow code.


return [


'provides' => [





'aliases' => [



'DNS1D' => Milon\Barcode\Facades\DNS1DFacade::class,

'DNS2D' => Milon\Barcode\Facades\DNS2DFacade::class,



Step 2: Add Route

In second step we will add new two route for creating small example that way we can undestand very well. so first add bellow route in your routes.php file.


Route::get('barcode', '[email protected]');

Step 3: Add Controller Method

In this step we will add barcode() method in HomeController Controller file for our example. you can write bellow method on HomeController.

Controller Method

public function barcode()


return view('barcode');


Step 4: Add Blade file

This is a last step and you have to just create new blade file barcode.blade.php and put bellow code on that file.




<style type="text/css">


padding-left: 20px;



<div class="row">

<div class="col-md-8 col-md-offset-2">

<h1 class="text-primary" style="text-align: center;">Laravel 5 Barcode Generator Using milon/barcode</h1>



<div class="container text-center" style="border: 1px solid #a1a1a1;padding: 15px;width: 70%;">

<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('11', 'C39')}}" alt="barcode" />

<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('12', 'C39+')}}" alt="barcode" />

<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('13', 'C39E')}}" alt="barcode" />

<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('14', 'C39E+')}}" alt="barcode" />

<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('15', 'C93')}}" alt="barcode" />



<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('19', 'S25')}}" alt="barcode" />

<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('20', 'S25+')}}" alt="barcode" />

<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('21', 'I25')}}" alt="barcode" />

<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('22', 'MSI+')}}" alt="barcode" />

<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('23', 'POSTNET')}}" alt="barcode" />



<img src="data:image/png;base64,{{DNS2D::getBarcodePNG('16', 'QRCODE')}}" alt="barcode" />

<img src="data:image/png;base64,{{DNS2D::getBarcodePNG('17', 'PDF417')}}" alt="barcode" />

<img src="data:image/png;base64,{{DNS2D::getBarcodePNG('18', 'DATAMATRIX')}}" alt="barcode" />



Try this.. if you more learn from here : milon/barcode.

Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: