How To Create Barcode Generator In Laravel 9

In this article, we will see how to create a barcode generator in laravel 9. In this example, we will use the milon/barcode package and we will implement it in our barcode example in laravel 9. milon/barcode package provide many functionalities and different options to generate barcode. It provides several barcodes like C39E, C39, C39E+, C93, S25, S25+, C39+, I25, I25+, PDF417, etc.

So, let's see how to generate barcode using milon/barcode package in laravel 9, barcode generator in laravel 9, and laravel 9 barcode generator.

Step 1: Install Laravel 9 For Barcode Generator

Step 2: Install milon/barcode Package

Step 3: Add Service Provider And Aliase

Step 4: Create Controller

Step 5: Add Route

 

Step 1: Install Laravel 9 For Barcode Generator

In this step, we will install the laravel 9 application using the following command.

composer create-project --prefer-dist laravel/laravel laravel_9_barcode_generator

 

 

Step 2: Install milon/barcode Package

In this step, we will install the milon/barcode package using the following command.

composer require milon/barcode

You can also edit your project's composer.json file to require milon/barcode.

"require": {
    "milon/barcode": "^9.0"
}

Next, update Composer from the Terminal.

composer update

 

Step 3: Add Service Provider And Aliase

In this step, add the service provider.

'providers' => [
    // ...
    Milon\Barcode\BarcodeServiceProvider::class,
]

If you want to change Bar-code's settings (Store Path etc.), you need to publish its config file(s). For that, you need to run in the terminal.

# Laravel 5.x
php artisan vendor:publish

Now add the alias.

'aliases' => [
    // ...
    'DNS1D' => Milon\Barcode\Facades\DNS1DFacade::class,
    'DNS2D' => Milon\Barcode\Facades\DNS2DFacade::class,
]

 

 

Step 4: Create Controller

Now, we will create a BarcodeGeneratorController.php file.

app\Http\Controllers\BarcodeGeneratorController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class BarcodeGeneratorController extends Controller
{
    public function barcode()
	{
	    return view('barcode');
	}
}

 

Step 5: Add Route

Now, we will add routes in the web.php file.

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\BarcodeGeneratorController;
/*
|--------------------------------------------------------------------------
| 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('/', function () {
    return view('welcome');
});

Route::get('generate/barcode', [BarcodeGeneratorController::class,'barcode']);

 

 

Step 6: Create Blade File 

Now, create a barcode.blade.php file to generate a barcode.

resources\views\barcode.blade.php

<html>	
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>How To Create Barcode Generator In Laravel 9 - Techsolutionstuff</title>
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
	</head>
	<div style="margin-left:265px; margin-right: 265px; margin-top: 40px;">
		<h2 class="text-primary" style="text-align: center;margin-bottom: 20px;">How To Create Barcode Generator In Laravel 9 - Techsolutionstuff</h2>
		<div style="text-align: center;">
			<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('10', 'C39')}}" alt="barcode" /><br><br>
			<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('123456789', 'C39+',1,33,array(0,220,150), true)}}" alt="barcode" /><br><br>
			<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('5', 'C39+',3,33,array(255,0,0))}}" alt="barcode" /><br><br>
			<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('11', 'C39+')}}" alt="barcode" /><br><br>
			<img src="data:image/png;base64,{{DNS1D::getBarcodePNG('25', 'POSTNET')}}" alt="barcode" /><br/><br/>
		</div>
	</div>
</html>

 


You might also like:

RECOMMENDED POSTS

FEATURE POSTS