Apr 20, 2024 | Laravel 11 Laravel
Hello Dev,
In this tutorial, I'll walk you through the process of generating barcodes within a Laravel 11 application using the picqer/php-barcode-generator Composer package.
We'll utilize the picqer/php-barcode-generator package to create barcodes efficiently. I'll provide a straightforward example demonstrating how to generate barcodes with both TYPE_CODE_128 and TYPE_CODE_39 types.
Follow the steps below to integrate barcode generation functionality into your Laravel 11 projects:
To generate a barcode in a Laravel 11 application using the picqer/php-barcode-generator package, follow these steps:
Step 1: Install Laravel 11If you haven't already, create a new Laravel project:
composer create-project --prefer-dist laravel/laravel laravel-barcodeStep 2: Install picqer/php-barcode-generator Package
Navigate to your project directory and install the picqer/php-barcode-generator package:
composer require picqer/php-barcode-generatorRead Also: implementing drag-and-drop file uploads with dropzone.js in laravel 11 1: Laravel Generate Barcode Example
Here, we will create simple route for generating Barcode, Then i will show you output bellow as well:
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('000007845619', $generatorPNG::TYPE_CODE_128); return response($image)->header('Content-type','image/png'); });Output
Here, we will create simple route for generating Barcode:
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('000007845619', $generatorPNG::TYPE_CODE_128); Storage::put('barcodes/demo.png', $image); return response($image)->header('Content-type','image/png'); });Read Also: determining user location in laravel 11 using ip addresses 3: Laravel Generate Barcode with Blade Example
Here, we will create simple route for generating Barcode, Then i will show you output bellow as well:
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('0008965741230', $generatorHTML::TYPE_CODE_128); return view('barcode', compact('barcode')); });resources/views/barcode.blade.php
<!DOCTYPE html> <html> <head> <title>Generating Barcodes in Laravel 11 with picqer/php-barcode-generator -- ITErrorSolutuin.com</title> </head> <body> <h1>Generating Barcodes in Laravel 11 with picqer/php-barcode-generator -- ITErrorSolutuin.com</h1> <h3>Product: 0008965741230</h3> {!! $barcode !!} </body> </html>
Thank you for your encouragement! If you have any questions or need further assistance, feel free to ask. I'm here to help!
"Hey there! I'm a full-stack developer and proud owner of ItErrorSolution.com, based right here in India. I love nothing more than sharing handy tips and tricks with my fellow developers through easy-to-follow tutorials. When it comes to coding, I'm all about PHP, Laravel, Angular, Vue, Node, JavaScript, jQuery, CodeIgniter, and Bootstrap – been hooked on them forever! I'm all about putting in the work and staying committed. Ready to join me on this journey to coding?"