Laravel Barcode Generator: Create & Print Barcodes & QR Codes Easily
Chapters10
Introduces the million/barcode package and explains it is a Laravel wrapper around an existing barcode generator to add Laravel compatibility.
Tony Xhepa demos a Laravel barcode generator using the million/barcode package, showing how to create, preview, download, and manage barcode and QR code SVG/PNGs with Livewire on Laravel 13.
Summary
Tony Xhepa walks through setting up and using the million/barcode package to generate barcodes and QR codes in a Laravel app. He notes that the package is a wrapper with Laravel compatibility, and shows installation via composer, including Laravel 13 support. The video walks through a live demo: generating a barcode by value, choosing formats like Code 128 or QR, and optionally adding a label, then exporting as PNG. He also demonstrates a history list of recently created barcodes, with options to view, download, and delete entries. The code example centers on Laravel 13 with Livewire, including a Barcode model, migration, and a dedicated Enam BarcodeFormat enum to handle formats like C28, C39, and QR. The UI consists of a form for value, format, and label, a live preview of the barcode SVG, and download buttons for PNG. He drills into the renderBarcode logic, showing how the code branches for 2D QR codes vs 1D barcodes, and how the PNG is produced and streamed for download. Finally, Tony points viewers to the GitHub repository (million/barcode) and emphasizes the ease of creating barcodes and QR codes with Laravel using this setup.
Key Takeaways
- Installing the million/barcode package is as simple as composer require million/barcode, with explicit Laravel 13 support demonstrated.
- The UI lets you generate barcodes by value and format (Code 128, Code 39, QR Code) and optionally add a label, then download a PNG preview.
- Barcode rendering differentiates between QR codes (2D) and 1D barcodes, using the DNS 2D and DNS 1D render paths to produce SVGs and PNGs.
- The codebase includes a Barcode model and migration (value, format, label) and an Enam BarcodeFormat enum to manage supported formats.
- Livewire is used to wire up the form, validation, and dynamic rendering/preview on the page.
- A history feature stores generated barcodes and provides quick view/download/delete actions for past items.
- Tony also highlights that the PNG can be downloaded directly from the preview block, making it a complete, drop-in solution for barcodes and QR codes in Laravel.
Who Is This For?
Laravel developers who want an easy, drop-in solution to generate and print barcodes and QR codes, especially those using Laravel 13 and Livewire who need a live preview and downloadable PNGs.
Notable Quotes
"Hello friends, Tony here."
—Intro greeting setting the tone of the tutorial.
"we can click and we can generate a barcode."
—Demonstrates the core interaction for creating barcodes.
"This package is just a wrapper of that package and adds compatibility for laravel."
—Explains the package relationship and Laravel compatibility.
"we are on Laravel 13 with live wire."
—Highlights the targeted stack and tech setup.
"download also the PNG."
—Shows the export capability for generated barcodes.
Questions This Video Answers
- how to install million/barcode in a Laravel 13 project
- how to generate barcodes and QR codes in Laravel with Livewire
- how to download barcode PNGs in Laravel using the DNS renderers
- what is Enam BarcodeFormat and how is it used in Laravel barcode generation
- how to implement a barcode history and deletion feature in Laravel apps
Full Transcript
Hello friends, Tony here. Welcome. In today's video, I'm going to work with this uh million barcode package for Laravel. So if you go to GitHub million/barcode. So this is a barcode generator package inspired by this one. So actually I use that package underline classes for generating barcodes. This package is just a wrapper of that package and adds compatibility for laravel. Now I use the following classes of that package and you can see the classes installation is very easy just composer require and yeah also has support for the Laravel 13 version and yeah has 1.5 stars.
I have created a project with the cloud code and implement this which is right here the project and let me just show you also let me just uh come here and operate around the mpm around dev. Okay, now let's go and register with the fake filler as always. And here I have this barcode generator. We can click and we can generate a barcode. Here we need the value for example the product uh ID. And if we put a value here something random. We choose the format because we have uh code 128 39 138 or QR code.
So let's choose this one. Optional you can add a label. So for example uh I'm going to say generate and here it's going to generate that barcode. We have the value we have the format and we can download also the PNG. So if I click here is now the barcode PNG and here is that. Okay. We can create also the QR code and here is the list of the recent recent history. So what we have created. So this is format code 128 also we have this QR code and we can see yeah it looks like this or we can create a new one.
So let's add a number here and let's choose QR code label is optional somewhere. Let's click generate and yeah here is the preview of this QR code and we can download also that as PNG. Yeah, we can view them and we can delete. Now let's see the or let's just show you if I click. Yeah, it's deleted. Now let's show you the code. This is on Laravel 13 with live wire. So I'm going to open first the model which is the barcode or let's open the barcode migration first. I have string value string format and the label which is by default new label.
And let me just zoom it a little bit like this. Okay. And then let's open the barcode model. And here we just have the prototype filable pass in the value format and the label. Now here I have used the Laravel defaults uh Laravel 12 but you can if you want you can use the Laravel 13 attribute filable that is not the difference here. Now let's open also what I have created is uh this enam barcode format and here we have the case for C28 C39 and so on also the QR code and the label and also public function is QR code which returns the boolean then let's open the web routes And here I have added this route live wire for barcodes as I told you I'm using live wire here and I'm using pages component and we have this barcodes page which is right here.
All that logic is inside this file. I added the title and then string for value format using that barcode format enam and getting the default C 128 value and the label is going to be an empty string by default also this one also created this barcode SVG by default is not then we have the generate method validate first the data value is going to be required string max 255 format is going to be required part and rule enam pass in the barcode format enam class and the label is a bit label string and max 100.
Then we're going to create that barcode using the barcode model passing the validated. So adding the value format and the label in the database storing them in the database and then this barcode SVG when it assigned this render barcode pass in the value and the format. So we have this render barcode method which is right here. So render barcode passing the value and the format. This is going to return a string. So barcode format is able with barcode format from passing the format here. And then we want to check if barcode format is QR code because we have that method on the barcode format in use that where to say return new DNS 2D get barcode SVG pass in the value format and 44.
You can read more on that uh package. Otherwise, we enter a new DNS 1D get barcode SVG passing the value format 260 black and true. Okay, so this is what we have done here. Then we have also this view from history method pass in the ID and saying barcode barcode find or fail passing that ID and this value barcode value format barcode format label and then assigning that this barcode SVG this render barcode passing the barcode value and barcode format we get here also we have the download method validate the value in the format and then PNG to save this render barcode PNG which we have also that render barcode PNG method right here pass in the value in the format first we get the format here we're going to check if that is QR code if that is QR code we say return base 64 decode new DNS 2D get barcode PNG pass in the value format 1010 otherwise this 64 decode New DNS 1D get barcode PNG value format 260.
So we are on the download. So we get that PNG and then we turn response stream the download function USPNG echo PNG and also barcode PNG content type image. Then we have a delete method to delete history barcode first or find or fail. And if that if this value is triple label with barcode value and this format triple label with barcode format we have to say this barcode SVG to null and delete. Okay. So first we set this barcode SVG if that barcode SVG is with format label also here barcode format try from format label render barcode.
Okay. Okay. Then we have the HTML. So the barcode generator here as heading and then generator form heading generate barcode. We have the value we have a format which is a select for each barcode format in them and then we have also the label optional and we have a type. So while loading remove generate and while loading generate flex button then we have a barcode preview which is this one here. If we have that back code SVG flax head in preview and we displaying we render here the back that back SVG displaying the value here and also this format label passing the format and the button to download the PNG.
So if I click here the value of format and the download button and when you click we are going to invoke this download method else your barcode will appear here. So we have this thing but then we have also the history which is this table here. If history is empty we will say no barcode generated yet. else add a table make a for each and that's it the project okay friends this is how easy it is to create barcodes and QR codes with lar values in this package that's it all about this video now if you like such a videos don't forget to subscribe to my channel like the video share with your friends and see you in the next one all the best thank you very
More from Tony Xhepa
Get daily recaps from
Tony Xhepa
AI-powered summaries delivered to your inbox. Save hours every week while staying fully informed.









