Laravel 9 Barcode Generator Example

Websolutionstuff | Mar-26-2022 | Categories : Laravel PHP

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

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

Step 1 : Install Laravel 9

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

In this step, we will create laravel 9 application using the below command.

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

 

 

Step 2 : Install milon/barcode Package

After installation of project, you need to install milon/barcode Package using the below 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

Once this operation completes, the final step is to add the service provider. Open, and add a new item to the provider's array.

'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 create a controller app\Http\Controllers\BarcodeController.php and add the below command.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

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

 

Step 5 : Add Route

We need to add route for generating Barcode and view file.

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\BarcodeController;
/*
|--------------------------------------------------------------------------
| 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('barcode', [BarcodeController::class,'barcode']);

 

 

Step 6 : Create Blade File 

Now, create barcode.blade.php file for generate Barcode in this path resources\views\barcode.blade.php and add below html code.

<html>	
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>Laravel 9 Barcode Generator Example - Websolutionstuff</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;">Laravel 9 Barcode Generator Example - Websolutionstuff</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>

Output :

laravel_9_barcode_generator_example_output


You might also like :

Recommended Post
Featured Post
How To Get Hourly Data In MySQL
How To Get Hourly Data In MySQ...

In this tutorial, we will see how to get hourly data in mysql. Many times we need to get hourly data or we are required...

Read More

Feb-04-2022

Laravel tips: DB Models and Eloquent
Laravel tips: DB Models and El...

In the realm of web development, an efficient and robust data handling mechanism is paramount. Laravel, a PHP web applic...

Read More

Oct-11-2023

How to Disable Right Click using jQuery
How to Disable Right Click usi...

In this small post i will show you how to disable right click using jquery. Here, we will disable right click on pa...

Read More

Aug-18-2021

How to Create New Component in Angular 17 using Command
How to Create New Component in...

Welcome to this comprehensive tutorial where I'll guide you through the process of creating a new component in Angul...

Read More

Mar-22-2024