Barcode Generator in Laravel 8 Tutorial

Reading Time: 4 minutes

A barcode or bar code is a method of representing data in a visual, machine-readable form. Inside this article we will see the concept of Barcode generator in Laravel 8. There are several composer package available to generate barcode in laravel application.

This tutorial is a step by step guide to create a barcode generator. What is a Barcode?

A barcode or bar code is a method of representing data in a visual, machine-readable form.

Let’s get started.

Laravel Installation

We will create laravel project using composer. So, please make sure your system should have composer installed. If not, may be this article will help you to Install composer in system.

Here is the command to create a laravel project-

composer create-project --prefer-dist laravel/laravel blog

To start the development server of Laravel –

php artisan serve


Assuming laravel already installed inside your system.

Install Barcode Generator Package

Open project into terminal and run this command to install.

$ composer require milon/barcode

It will install the needed files inside /vendor folder of application.

Configure Barcode Generator Package

Open app.php from /config folder of application.

Search for providers, add this line of code into array.



Search for aliases, add this line of code into array.


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

Create Route

Open web.php from /routes folder.

Add this route into it.

# Add this to header
use App\Http\Controllers\BarcodeController;


Route::get('barcode', [BarcodeController::class, 'index'])->name('barcode.index');

Create Controller

Open project into terminal and run this artisan command.

$ php artisan make:controller BarcodeController

It will create BarcodeController.php file into /app/Http/Controllers folder.

Open BarcodeController.php and write this complete code into it.


namespace App\Http\Controllers;

use Illuminate\Http\Request;

class BarcodeController extends Controller
    public function index()
        return view('barcode');

Create Blade Layout File

Go to /resources/views folder and create a file with name barcode.blade.php.

Open barcode.blade.php and write this complete code into it.

<!DOCTYPE html>

    <title>Barcode Generator Laravel 8 Tutorial</title>
    <link rel="stylesheet" href="">

    <div class="container">
        <h3>Barcode Generator Laravel 8 Tutorial</h3>
        <div class="row">
            <div class="col-md-8">
                <div>{!! DNS1D::getBarcodeHTML('4445645656', 'C39') !!}</div><br />
                <div>{!! DNS1D::getBarcodeHTML('4445645656', 'POSTNET') !!}</div><br />
                <div>{!! DNS1D::getBarcodeHTML('4445645656', 'PHARMA') !!}</div><br />
                <div>{!! DNS2D::getBarcodeHTML('4445645656', 'QRCODE') !!}</div><br />

  • getBarcodeHTML() This is method in which we need to pass text and barcode format type.

Application Testing

Run this command into project terminal to start development server,

php artisan serve


To learn more about this composer package and it’s settings, Click here to go.

We hope this article helped you to learn about Barcode Generator in Laravel 8 Tutorial in a very detailed way.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Sanjay KumarHello friends, I am Sanjay Kumar a Web Developer by profession. Additionally I'm also a Blogger, Youtuber by Passion. I founded Online Web Tutor and Skillshike platforms. By using these platforms I am sharing the valuable knowledge of Programming, Tips and Tricks, Programming Standards and more what I have with you all. Read more