How to make a Barcode generator in Laravel 11

How to make a Barcode generator in Laravel 11

In this article, we will see how can we make a barcode generator in Laravel 11. After learning this article you will be able to make your system which will generate a barcode. You can generate barcodes in different ways like a PNG, jpg, HTML view and much more.

Step #01: Fresh Laravel project

First, we need a fresh Laravel project to run this given command to make a project.

Composer create-project Laravel/Laravel codegen

Step #02: Installing the required package

In this system, we will use a package which will allow us to generate barcodes. After creating the project run this command. Read more about the package

composer require picqer/php-barcode-generator


Step #03: Creating controller

After that we need a controller, run the given command to make a controller and then update with given code.

Php artisan make:controller Code

Update the controller with this code.  App/https/controllers/code.php.

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Picqer\Barcode\BarcodeGeneratorHTML;
class Code extends Controller
    public function code(){
        $genertorHTML = new BarcodeGeneratorHTML();
        $barcode = $genertorHTML->getBarcode('98245226222', $genertorHTML::TYPE_CODE_128);
        return view('code', compact('barcode'));


Step #04: View creating

After that create a view file. Resouces/views/code.blade.php, and update with the given code.

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>How to make barcode generator in Larvel 11</title>
    <h2>Code: 98245226222</h2>
    {!! $barcode !!}


Step #05: Routes creating

So here Is the last and main step is route. Open web.php which is available in routes/web.php and update with given code.

use App\Http\Controllers\Code;
use Illuminate\Support\Facades\Route;
Route::get('/', [Code::class, 'code']);


Step #06: Testing System

So start server and test your Barcode.

Php artisan server


No Comment posted Yet!

Leave a Reply

OK! You can skip this field.