Barcode Generator in Laravel 8 Tutorial

Share this Article
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.

Installation of Laravel Application

Laravel Installation can be done in two ways.

  • Laravel Installer
  • By using composer

Laravel Installer

To install Laravel via Laravel installer, we need to install it’s installer first. We need to make use of composer for that.

$ composer global require laravel/installer

This command will install laravel installer at system. This installation is at global scope, so you type command from any directory at terminal. To verify type the given command –

$ laravel

This command will open a command palette of Laravel Installer.

To create ad install laravel project in system,

$ laravel new blog

With the name of blog a laravel project will be created at your specified path.

By using composer

Alternatively, we can also install Laravel by Composer command create-project.

If your system doesn’t has composer Installed, Learn Composer Installation Steps.

Here is the complete command to create a laravel project-

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

After following these steps we can install a Laravel application into system.

To start the development server of Laravel –

$ php artisan serve

This command outputs –

Starting Laravel development server:

Assuming laravel already installed at 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

Open project to terminal and type the command 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.

Find More on Laravel 8 Articles here