ItSolutionStuff.com

Laravel Barcode Generator using milon/barcode Example

By Hardik Savani • November 6, 2024
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:

Preview:

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.

config/app.php

return [

......

'provides' => [

......

......,

Milon\Barcode\BarcodeServiceProvider::class

],

'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.

app/Http/routes.php

Route::get('barcode', 'HomeController@barcode');

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.

resources/views/barcode.blade.php

@extends('layouts.app')


@section('content')

<style type="text/css">

img{

padding-left: 20px;

}

</style>

<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>

</div>


<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" />

<br/>

<br/>

<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" />

<br/>

<br/>

<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" />

</div>


@endsection

Output:

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

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Get Single Row from Database in Laravel?

Read Now →

How to Add Two Factor Authentication with SMS in Laravel?

Read Now →

Laravel Eloquent whereHas() Condition Example

Read Now →

Laravel Search Case Insensitive Query Example

Read Now →

How to Generate Random Unique Number in Laravel?

Read Now →

How to Change Column Length using Laravel Migration?

Read Now →

How to Update Enum Value in Laravel Migration?

Read Now →

Laravel Blade Include File If Exists Example

Read Now →

Laravel Eloquent withSum() and withCount() Example

Read Now →

Laravel Livewire Delete Confirmation Example

Read Now →

How to Get Last 30 Days Record in Laravel?

Read Now →

Laravel Redirect Back with Input and Error Messages Example

Read Now →

Laravel Google reCaptcha using anhskohbo/no-captcha Example

Read Now →

How to Count Files in a Directory using Laravel?

Read Now →