Home Laravel How to generator Barcode by using milon/barcode in Laravel?

How to generator Barcode by using milon/barcode in Laravel?

by Shahriar Sagor

Today now in this post i am going to give you an example of how to generate the barcode in laravel application. We can easily create the barcode by using milon/barcode package that provide the several way to generate QR Code and also barcode. If we need to the generate barcode for our products then we can generate barcode sticker in our laravel application by using milon/barcode package. So here I will added a preview of barcode after the finish example. You can find a output like you want. Now It’s provide the several barcode as like Qr Code, PDF417, C39,C39+, C39E,C39E+, C93, S25,S25+, I25,I25+ etc.

Step 1: Installation

Today now in first step we will install the milon/barcode package for generate the bar-code image. So at first need to fire the bellow command in our cmd or terminal:

composer require milon/barcode

Okay now we need to add the provider path and alias path in the config/app.php file. So now open that file and add the bellow code.


return [
	'provides' => [
	'aliases' => [
		'DNS1D' => Milon\Barcode\Facades\DNS1DFacade::class,
        'DNS2D' => Milon\Barcode\Facades\DNS2DFacade::class,
Step 2: Add Route

Now in the second step we will add the new two route for creating this small example on that way we can understand very well.

So at first add the bellow route in your routes.php file.


Route::get('barcode', 'HomeController@barcode');
Step 3: Add Controller Method

Now in this step we need to add barcode() method in our HomeController Controller file for our this example. We need to write the bellow method on HomeController.

Controller Method

public function barcode()
    return view('barcode');
Step 4: Add Blade file

Now we are in last step and we need to just create the new blade file as name barcode.blade.php and then put the 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" />


Read Also: Generate Captcha code and Validation by using BotDetect package in laravel

Thanks for read. I hope it help you. For more you can follow us on facebook


You may also like