How to Generate Barcode in Laravel 10

To generate barcodes in Laravel, you can utilize a barcode generation library. One popular library is "Picqer/php-barcode-generator." Here's how you can set it up in your Laravel project:

Step 1: Install the Library

 Run the following command:

Step 2: Generate Barcodes

routes/web.php 

<?php
  
    use Illuminate\Support\Facades\Route;
      
    /*
    |--------------------------------------------------------------------------
    | Web Routes
    |--------------------------------------------------------------------------
    |
    | Here is where you can register web routes for your application. These
    | routes are loaded by the RouteServiceProvider within a group which
    | contains the "web" middleware group. Now create something great!
    |
    */
      
    Route::get('barcode', function () {
      
            $generatorPNG = new Picqer\Barcode\BarcodeGeneratorPNG();
            $image = $generatorPNG->getBarcode('000005263635', $generatorPNG::TYPE_CODE_128);
      
            return response($image)->header('Content-type','image/png');
     });

Step 3: Generate Barcodes  and Save 

routes/web.php 

<?php
  
    use Illuminate\Support\Facades\Route;
      
    /*
    |--------------------------------------------------------------------------
    | Web Routes
    |--------------------------------------------------------------------------
    |
    | Here is where you can register web routes for your application. These
    | routes are loaded by the RouteServiceProvider within a group which
    | contains the "web" middleware group. Now create something great!
    |
    */
      
    Route::get('barcode-save', function () {
      
            $generatorPNG = new Picqer\Barcode\BarcodeGeneratorPNG();
            $image = $generatorPNG->getBarcode('000005263635', $generatorPNG::TYPE_CODE_128);
      
            Storage::put('barcodes/demo.png', $image);
      
            return response($image)->header('Content-type','image/png');
     });

Step 4: Laravel Generate Barcode with Blade File

routes/web.php 

<?php
  
    use Illuminate\Support\Facades\Route;
      
    /*
    |--------------------------------------------------------------------------
    | Web Routes
    |--------------------------------------------------------------------------
    |
    | Here is where you can register web routes for your application. These
    | routes are loaded by the RouteServiceProvider within a group which
    | contains the "web" middleware group. Now create something great!
    |
    */
      
    Route::get('barcode-blade', function () {
      
            $generatorHTML = new Picqer\Barcode\BarcodeGeneratorHTML();
            $barcode = $generatorHTML->getBarcode('0001245259636', $generatorHTML::TYPE_CODE_128);
      
            return view('barcode', compact('barcode'));
     });

resources/views/barcode.blade.php

<!DOCTYPE html>
    <html>
    <head>
        <title>How to Generate Bar Code in Laravel? - webthestuff.com</title>
    </head>
    <body>
        
        <h1>How to Generate Bar Code in Laravel 10? - webthestuff.com</h1>
             
        <h3>Product: 0001245259636</h3>  
        {!! $barcode !!}
      
    </body>
    </html>

Now, see Try Your Diffrent Barcode as per your Requirement ,Thank You