Workflow
Custom Field Barcode

This example uses Custom Fields in combination with the package PHP Barcode Generator to display barcodes in each table row.

ID
Name
Barcode
In Stock
Created At
1
Arkansas Possum Pie
Yes
2024-05-09 14:16:50
2
Albacore Tuna Melt
No
2024-04-29 12:47:45
3
Π±ΠΎΡ€Ρ‰
Yes
2024-04-24 10:37:16
4
Bacalhau com natas
Yes
2024-05-10 18:05:31
5
Baba Ghanoush
No
2024-03-18 17:53:02
6
Bacon Cheeseburger
No
2024-04-09 21:18:04
7
Baked potato
No
2024-03-26 14:16:25
8
Baklava
No
2024-04-12 23:49:27
9
Bangers and mash
Yes
2024-05-04 10:29:34
10
Black Pudding
Yes
2024-04-01 05:41:07
Disclaimer: Table data is randomly generated for illustrative purposes only. The information here is not a reflection of the actual market and does not constitute business, financial, or medical advice.
πŸ”Ž View on GitHub
<?php
 
namespace App\Livewire\Examples\CustomFieldBarcodeTable;
 
use App\Models\Dish;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Carbon;
use PowerComponents\LivewirePowerGrid\Column;
use PowerComponents\LivewirePowerGrid\Footer;
use PowerComponents\LivewirePowerGrid\Header;
use PowerComponents\LivewirePowerGrid\PowerGrid;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
use PowerComponents\LivewirePowerGrid\PowerGridFields;
 
class CustomFieldBarcodeTable extends PowerGridComponent
{
public function setUp(): array
{
return [
Header::make()
->showSearchInput(),
 
Footer::make()
->showPerPage()
->showRecordCount(),
];
}
 
public function datasource(): ?Builder
{
return Dish::query();
}
 
public function fields(): PowerGridFields
{
$barcodeGenerator = new \Picqer\Barcode\BarcodeGeneratorPNG();
 
return PowerGrid::fields()
->add('id')
->add('name')
->add('in_stock', fn ($dish) => $dish->in_stock ? 'Yes' : 'No')
->add('created_at_formatted', fn ($dish) => Carbon::parse($dish->created_at))
->add('barcode', function (Dish $dish) use ($barcodeGenerator) {
return sprintf(
'<img src="data:image/png;base64,%s">',
base64_encode($barcodeGenerator->getBarcode($dish->id, $barcodeGenerator::TYPE_CODE_128))
);
});
}
 
public function columns(): array
{
return [
 
Column::make('ID', 'id')
->searchable()
->sortable(),
 
Column::make('Name', 'name')
->searchable()
->sortable(),
 
Column::make('Barcode', 'barcode'),
 
Column::make('In Stock', 'in_stock')
->searchable(),
 
Column::make('Created At', 'created_at_formatted'),
];
}
}
Code highlighting provided by Torchlight.dev

Here you can find all relevant packages installed on this demo.

Name
Version
Description
laravel/framework
v11
The Laravel Framework.
livewire/livewire
v3.4.12
A front-end framework for Laravel.
openspout/openspout
v4.24.0
PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way
picqer/php-barcode-generator
v2.4.0
An easy to use, non-bloated, barcode generator in PHP. Creates SVG, PNG, JPG and HTML images from the most used 1D barcode standards.
power-components/livewire-powergrid
v5.6.3
PowerGrid generates Advanced Datatables using Laravel Livewire.