jeffersongoncalves/filament-qrcode-field
Installation
composer require jeffersongoncalves/filament-qrcode-field
Publish the config (if needed):
php artisan vendor:publish --provider="JeffersonGoncalves\FilamentQrCodeField\FilamentQrCodeFieldServiceProvider" --tag="config"
First Use Case Add the QR Code field to a Filament form/resource:
use JeffersonGoncalves\FilamentQrCodeField\Fields\QrCode;
QrCode::make('qr_content')
->label('QR Code Content')
->required()
->default('https://example.com'),
Where to Look First
config/filament-qrcode-field.php for customization options (e.g., QR size, error correction level).QrCode field class in the source code for available methods.Basic Form Integration Use the field in a Filament form to generate/scan QR codes for dynamic content (e.g., user profiles, inventory items):
public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')->required(),
QrCode::make('qr_data')
->label('QR Payload')
->helperText('Scan this to access the resource.'),
]);
}
Resource-Specific Usage
Attach to a model’s getTableRecords() or getFormSchema() for CRUD operations:
public static function table(Table $table): Table
{
return $table
->columns([
// ...
Columns\QrCodeColumn::make('qr_data')
->label('QR Code')
->size(100), // Adjust size in pixels
]);
}
Dynamic Payloads Generate QR codes from computed data (e.g., encrypted tokens, API endpoints):
QrCode::make('auth_token')
->getStateUsing(function ($record) {
return encrypt($record->token);
})
->columnSpanFull(),
Validation & Sanitization Combine with Filament’s validation rules:
QrCode::make('url')
->rules(['url', 'max:2048'])
->dehydrateStateUsing(fn ($state) => str($state)->trim()),
renderUsing method:
QrCode::make('custom_qr')
->renderUsing(function ($state, $record) {
return view('custom.qr-renderer', ['content' => $state]);
});
QrCode::make('qr_code')
->label(__('filament-qrcode::fields.qr_code.label'))
->helperText(__('filament-qrcode::fields.qr_code.helper')),
QrCode::make('cached_qr')
->disk('public')
->path('qr-codes/{record_id}.png'),
Payload Length Limits
base64_encode(json_encode($data))).Filament Version Mismatch
composer.json.State Hydration Issues
getStateUsing returns null, the field may render blank.QrCode::make('qr_data')->default('fallback_url'),
CORS for Scanning
Access-Control-Allow-Origin headers or use a proxy.QrCode::make('debug_qr')
->dehydrateStateUsing(fn ($state) => logger()->debug('QR Payload:', ['data' => $state]) ?: $state),
Custom QR Libraries
Replace the default endroid/qr-code with another library (e.g., bacon/bacon-qr-code) by binding a service:
$this->app->bind(\JeffersonGoncalves\FilamentQrCodeField\Contracts\QrCodeGenerator::class, function () {
return new CustomQrGenerator();
});
Event Hooks Extend the field lifecycle via Filament’s events:
FilamentQrCodeField::registerCallback(
QrCode::class,
'beforeGenerate',
fn ($state, $record) => str($state)->replace('old', 'new')
);
Testing Mock the QR generator in PHPUnit:
$this->mock(\JeffersonGoncalves\FilamentQrCodeField\Contracts\QrCodeGenerator::class, function ($mock) {
$mock->shouldReceive('generate')->andReturn('<svg>mock-qr</svg>');
});
200px by default. Adjust via config:
'default_size' => 300, // in config/filament-qrcode-field.php
'error_correction' => 'H', // High error correction
How can I help you explore Laravel packages today?