How to Generate Barcode in Laravel 11 Example

In this article, we'll see how to generate barcodes in laravel 11 example. Here, we'll learn about laravel 11 creating barcodes. Here, we'll use milon/barcode composer package. milon/barcode package provides many functionalities and different options to generate barcodes. 

It provides several barcodes like C39E, C39, C39E+, C93, S25, S25+, C39+, I25, I25+, PDF417, etc. Also, you can generate dynamic height and width, color, and text.

How to Generate Barcode in Laravel 11

Step 1: Install Laravel 11 Application 

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

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



Step 2: Install milon/barcode Composer Package

Then, 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: Create Controller

Now, we will create a BarcodeController.php file.



namespace App\Http\Controllers;

use Illuminate\Http\Request;

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


Step 4: Define Route

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


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('generate/barcode', [BarcodeController::class,'barcode']);



Step 5: Create Blade File 

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


		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>How to Generate Barcode in Laravel 11 Example - Techsolutionstuff</title>
		<link rel="stylesheet" href="">
	<div style="margin-left:265px; margin-right: 265px; margin-top: 40px;">
		<h2 class="text-primary" style="text-align: center;margin-bottom: 20px;">How to Generate Barcode in Laravel 11 Example - 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/>


You might also like:


Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.