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
No
2024-09-26 21:14:57
2
Albacore Tuna Melt
No
2024-10-07 04:40:51
3
Π±ΠΎΡ€Ρ‰
Yes
2024-09-26 03:50:59
4
Bacalhau com natas
No
2024-09-29 14:54:40
5
Baba Ghanoush
No
2024-10-03 06:27:29
6
Bacon Cheeseburger
No
2024-09-11 15:12:26
7
Baked potato
Yes
2024-10-03 08:52:28
8
Baklava
Yes
2024-10-12 08:59:50
9
Bangers and mash
Yes
2024-10-03 15:01:01
10
Black Pudding
Yes
2024-10-03 00:01:29
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\Facades\PowerGrid;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
use PowerComponents\LivewirePowerGrid\PowerGridFields;
 
class CustomFieldBarcodeTable extends PowerGridComponent
{
public string $tableName = 'custom-field-barcode-table';
 
public function setUp(): array
{
return [
PowerGrid::header()
->showSearchInput(),
 
PowerGrid::footer()
->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