You are currently viewing How to Generate Barcode in Laravel 9 With Example
how to generate barcode in laravel 8

How to Generate Barcode in Laravel 9 With Example

Hi friends, in this tutorial we will learn how to generator dynamic barcode in Laravel 9 version. The most of beginner don’t know how to integration barcode in Laravel app.

And most of beginner avoid adopting this package but today first we will install Laravel barcode package from scratch with very simple steps. Am sharing my experience with you and I hope after this mini project you will be able to generate and integrate different barcode and QRcode in your Laravel projects.  

You can implement this package in your project for example Product Lable Prining, Invoice Barcode, Customer Code with Barcode.

  • Laravel Generate Product Barcode 
  • Laravel Generate Invoice Barcode
  • Laravel Generatoe Invoice Qrcode
  • Laravel Generatoe Customer Barcode
How to Generate Barcode in Laravel 9

How to Generate Barcode in Laravel 9 With Example

Step 01: In first step, If you haven’t installed Laravel in your system then you can run bellow command and get fresh Laravel project.

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

 

 

Step 02: Open your terminal and run .

composer require milon/barcode

Step 02: Open config/app.php and add below code.

 

<?php
return [
'providers' => [
....
....
....
Milon\Barcode\BarcodeServiceProvider::class,
],

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

Step 03: Open your terminal in your project and create Controller
php artisan make: controller ProductController

Step 04: to get the data from the database we need at lease model so create model run this command in your terminal.
php artisan make:model Product -m
Stpe 05: To migrate the table we run migrating command.
php artisan migrate.
Step 06: Open your controller in project app direct and write the following function.
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Barcode;
class BarcodeController extends Controller
{
public function create(){
$barcode = Barcode::all();
return view('barcode.create',[
'barcode_list' => $barcode
]);
}
}

How to Generate Barcode in Laravel 9 With Example

Step 07 : Go to resources folder in view create new view with the name of product

@extends('layouts.app')

@section('title', 'Lravel Barcode ')

@section('sidebar')


@include('layouts.navbar')
@stop

@section('content')
<div class="container item-align-center">
<h1 class="text-center">Barcode C128</h1>
<table border="2">
<thead>
<th width="100px">id</th>
<th>Product Name</th>
<th>Product Code</th>
<th class="text-center">Barcode</th>
</thead>
<tr>
@foreach($barcode_list as $key => $barlist)


<td class="text-center">{{$barlist->id}}</td>
<td>{{$barlist->name}}</td>
<td>{{$barlist->barcode}}</td>
<td class="text-center"> {!! DNS1D::getBarcodeHTML($barlist->barcode, "C128",1.4,22) !!}</td>
</tr>
@endforeach
</table>
</div>

@stop
<style>
table{
margin-left: 300px;
border: 2px solid navy;
widows: 100%;


}
table th {
border: 2px solid navy;
text-align: center;
}
table tr {
border: 2px solid navy;
}
table td{
border: 2px solid navy;
}

</style>

 

 

How to Generate Barcode in Laravel 9 With Example

Step 08: For setup your route. Go to route direct and open web.php.

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\BarcodeController;



Route::get('create', [BarcodeController::class, 'create']);

Suggested Article:

Leave a Reply