Laravel Barcode Generator using milon/barcode Example
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
Try this.. if you more learn from here : milon/barcode.
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. 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, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Get Single Row from Database in Laravel?
- How to Add Two Factor Authentication with SMS in Laravel?
- Laravel Eloquent whereHas() Condition Example
- Laravel Search Case Insensitive Query Example
- How to Generate Random Unique Number in Laravel?
- How to Change Column Length using Laravel Migration?
- How to Update Enum Value in Laravel Migration?
- Laravel Blade Include File If Exists Example
- Laravel Eloquent withSum() and withCount() Example
- Laravel Livewire Delete Confirmation Example
- How to Get Last 30 Days Record in Laravel?
- Laravel Redirect Back with Input and Error Messages Example
- Laravel Google reCaptcha using anhskohbo/no-captcha Example
- How to Count Files in a Directory using Laravel?