Laravel

How To Generate Barcode In Laravel 8

Pinterest LinkedIn Tumblr

How To Generate Barcode In Laravel 8

Step 1: Create the application

We need to run command to create Laravel 8 projects.

composer create-project --prefer-dist laravel/laravel laravel-8-barcode-generator

Step 2: Install picqer/php-barcode-generator Package

composer require picqer/php-barcode-generator

Step 3: Create Route

Now I am going to create route for calling controller and function.

routes/web.php

<?php

Route::view('barcode', 'barcode');

Step 4: Create Blade file

resources/views/barcode.blade.php

<!DOCTYPE html>
<html>
   <head>
      <title>Barcode Generator In Laravel 8 </title>
      <!-- CSS only -->
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
      <!-- Js only -->
   </head>
   <body>
      <div class="container">
         <div class="jumbotron">
            <div class="container text-center">
               <h2> 
                  Barcode Generator In Laravel 8
               </h2>
            </div>
         </div>
         <div class="container text-center d-flex align-items-center justify-content-center">
            <h3>Product 2: MAC-1200</h3>
            @php
                $generatorPNG = new Picqer\Barcode\BarcodeGeneratorPNG();
            @endphp
            <img src="data:image/png;base64,{{ base64_encode($generatorPNG->getBarcode('MAC-1200', $generatorPNG::TYPE_CODE_128)) }}">
         </div>
    </div>
   </body>
</html>

Run Project

php artisan serve
http://localhost:8001/barcode

Git: https://github.com/siddharth018/laravel-8-barcode-generator

Write A Comment