Laravel 9 Barcode Generator Example
Hello All,
This example is focused on laravel 9 generate barcode. Here you will learn how to generate barcode in laravel 9. This article will give you a simple example of how to create a barcode in laravel 9. this example will help you how to save generated barcode in laravel.
In this example, we will generate a barcode using picqer/php-barcode-generator composer package. I will give you a very simple example of generating Barcode with TYPE_CODE_128 and TYPE_CODE_39 types.
Let's see the below step and you can generate bar code in your laravel 9 projects as well.
Install Laravel 9
This is optional; 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 first step we will install picqer/php-barcode-generator Package that provides to generate Barcode in laravel application. So, first open your terminal and run bellow command:
composer require picqer/php-barcode-generator
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('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 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('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 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('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? - ItSolutionStuff.com</title>
</head>
<body>
<h1>How to Generate Bar Code in Laravel 9? - ItSolutionStuff.com</h1>
<h3>Product: 0001245259636</h3>
{!! $barcode !!}
</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 9 Google Charts Tutorial Example
- Laravel 9 Summernote Editor with Image Upload
- Laravel 9 Socialite Login with Facebook Account Example
- Laravel 9 Get Current Logged in User Data Example
- Laravel 9 Pagination Example Tutorial
- Laravel 9 Multi Auth: Create Multiple Authentication in Laravel
- How to Get Last Executed Query in Laravel 9?
- Laravel 9 Drag and Drop File Upload with Dropzone JS
- Laravel 9 Cron Job Task Scheduling Tutorial
- Laravel 9 Livewire CRUD using Jetstream & Tailwind CSS
- Laravel 9 REST API Authentication using Sanctum Tutorial
- Laravel 9 PDF | Laravel 9 Generate PDF File using DomPDF