Laravel Barcode generation tutorial


Barcode system integration with an application is really most wanted feature in the current development trend. It makes the workflow of your application faster and gives a better user experience. Barcode system is not so difficult to implement in your laravel project. Here in this post, I'll cover why Barcode is important for the application, what are the use case, how to generate barcode in Laravel application and how to read barcode in laravel and input in your application with a step by step instruction.

 

Importance

Suppose, we have a product table in our application database, where 10K or more products exist and each product has a unique ID something like P-00001, P-00002, P-00003 and so on. If we make an invoice for a customer we have to input one or more product code manually in the search box and find, that is a time-consuming task. In the situation, we can easily solve the problem by using a barcode to each product code. When we'll make an invoice for our customer we just have to scan the barcode by a barcode reader and the barcode reader instantly input the product code automatically so that we don't have to manually input it on the search box. It makes the workflow so faster and error-free.

 

Barcode Use Case

 

  • Barcode for Product.
    Each product will have a barcode so that we can easily read the barcode and find them quickly when searching for a product or making an invoice for the customer.
  • Barcode for Invoice.
    We can use barcode for each invoice so that we can easily find the specifics invoice when we need without inputting the long invoice code manually.
  • Barcode for Employee ID/Student ID/Customer ID/Service ID
    We can use barcode any unique ID. So that we can find the record quickly and do everything related to that ID.

    Here I have listed a few common use case. We can use barcode for each thing which has a unique identifier in our application.

 

Barcode Generation

Follow the steps for Generating barcode in your Laravel application. 

Step 01: Install milon/barcode package in your Laravel application. You can choose different milon/barcode version according to Laravel version.

composer require milon/barcode

 

Step 02: Barcode generation

In this part, I am generating barcode for product id something like P-00001, P-00002, P-00003 so on. You can generate any custom ID with Laravel ID generator package very easily!

Barcode printing sticker has a specific dimension. The most common dimension for the barcode sticker is 100X150 mm. According to that, we'll generate barcode which will have the product name, sale price, barcode and the product ID.

Controller Code

public function generateBarcode(Request $request){
	$id = $request->get('id');
	$product = Product::find($id);
	return view('barcode')->with('product',$product);
}

Barcode View Code

<div class="barcode">
    <p class="name">{{$product->name}}</p>
    <p class="price">Price: {{$product->sale_price}}</p>
    {!! DNS1D::getBarcodeHTML($product->pid, "C128",1.4,22) !!}
    <p class="pid">{{$product->pid}}</p>
</div>

We can use CSS for design adjustment according to our need.

DNS1D::getBarcodeHTML() takes 4 parameters.

1st parameter  for our provided code which we want to generate barcode,
2nd is for barcode type. Here we used C128 type barcode. Which allow alphanumeric barcode.
3rd is for barcode height
4th is for barcode width.

Laravel Barcode Example

laravel-barcode.png

 

Barcode Reader for Laravel

After generating barcode, print and tag to each product or printing barcode on invoice/customer card/student ID/employee ID etc. We need a barcode scanner machine to scan the barcode and input the scanned code in our application. For that, you can purchase a real barcode machine or you can use free Barcode Client-Server android application.

During barcode system development or production, we can use a free android application called Barcode Client-Server. Which helps us to scan barcode and send the scanned code to our application input box instantly. Let's see how can we use it.

 

 

Hope this post will help you to learn complete instruction about how to generate barcode in Laravel. If you find this helpful then please share the post with others so that it'll help them who are looking for Laravel barcode generation & barcode system integration tutorial.


Share on



Related Post - Latest Post


Laravel 8 authentication tutorial

What's new in Laravel 8

Laravel PDF generation tutorial

Laravel 7 Http facade

Laravel Validation Cheat Sheet