How to Generate Barcode in Laravel 11?
In this post, I will show you how to generate barcode in laravel 11 application. we will use picqer/php-barcode-generator composer package to create barcode in laravel 11.
In this example, we will generate a barcode using the picqer/php-barcode-generator composer package. I will give you a very simple example of generating a Barcode with TYPE_CODE_128 and TYPE_CODE_39 types.
Let's see the steps below, and you can generate a barcode in your Laravel 11 projects as well.
Install Laravel 11
This step is not required; however, if you have not created the Laravel app, then you may go ahead and execute the below command:
composer create-project laravel/laravel example-app
Install picqer/php-barcode-generator
In this step, we will install the `picqer/php-barcode-generator` package that provides a way to generate barcodes in a Laravel application. So, first, open your terminal and run the command below:
composer require picqer/php-barcode-generator
1: Laravel Generate Barcode Example
Here, we will create a simple route for generating a barcode. Then, I will show you the output below as well.
routes/web.php
<?php
use Illuminate\Support\Facades\Route;
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');
});
Output:
2: Laravel Generate Barcode and Save Example
Here, we will create a simple route for generating a Barcode:
routes/web.php
<?php
use Illuminate\Support\Facades\Route;
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');
});
3: Laravel Generate Barcode with Blade Example
Here, we will create a simple route for generating a barcode. Then I will show you the output below as well.
routes/web.php
<?php
use Illuminate\Support\Facades\Route;
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 11? - ItSolutionStuff.com</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="card mt-5">
<h3 class="card-header p-3">How to Generate Bar Code in Laravel 11? - ItSolutionStuff.com</h3>
<div class="card-body">
<h3>Product: 0001245259636</h3>
{!! $barcode !!}
</div>
</div>
</div>
</body>
</html>
Output:
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel 11 Chart using Highcharts JS Example
- Laravel 11 Socialite Login with Google Account Example
- Laravel 11 ChartJS Chart Example Tutorial
- Laravel 11 REST API with Passport Authentication Tutorial
- Laravel 11 One to Many Eloquent Relationship Tutorial
- How to Generate QR Code in Laravel 11?
- Laravel 11 Resize Image Before Upload Example
- Laravel 11 Multi Auth: Create Multiple Authentication in Laravel 11
- Laravel 11 Autocomplete Search from Database Example
- How to Get Last Executed Query in Laravel 11?
- Laravel 11 Select2 Ajax Autocomplete Search Example
- Laravel 11 Ajax CRUD Operation Tutorial Example
- Laravel 11 Cron Job Task Scheduling Tutorial