form->fill([ 'plant_id' => $this->plantId, 'leak_test_qr' => null, ]); } public function form(Form $form): Form { return $form ->statePath('filters') ->schema([ Section::make('') ->schema([ Select::make('plant_id') ->label('Plant') ->reactive() // ->options(Plant::pluck('name', 'id')) ->options(function (callable $get) { $userHas = Filament::auth()->user()->plant_id; return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); }) ->afterStateUpdated(function ($state, $set, callable $get, $livewire) { $plantId = $get('plant_id'); $this->plantId = $plantId; }) ->required(), TextInput::make('leak_test_qr') ->label('Leak Test QR') ->placeholder('Scan Leak Test QR') ->reactive() ->minLength(16) ->afterStateUpdated(function ($state, callable $get, callable $set) { $this->plantId = $get('plant_id'); $this->leakTestQr = $state; }) ->required() ->extraAttributes([ 'wire:keydown.enter' => 'processQr($event.target.value)', ]), ]) ->columns(2), ]); } public function processQr($value) { $plantId = $this->plantId; $this->leakTestQr = $value; $parts = explode('|', trim($value)); if (! preg_match('/^[^|]+\|[^|]+\|?$/', trim($value))) { Notification::make() ->title('Invalid QR Format') ->body("Expected format: ItemCode|SerialNumber
Received Format '$value'") ->danger() ->duration(5000) ->send(); } else { $iCode = trim($parts[0]); $sNumber = isset($parts[1]) ? trim($parts[1]) : null; if (strlen($iCode) < 6) { Notification::make() ->title('Invalid Item Code') ->body("Item code '$iCode' should contain minimum 6 digits!") ->danger() ->duration(5000) ->send(); } elseif (! preg_match('/^[a-zA-Z0-9]+$/', $iCode)) { Notification::make() ->title('Invalid Item Code') ->body("Item code '$iCode' should contain alpha numeric values!") ->danger() ->duration(5000) ->send(); } elseif (strlen($sNumber) < 9) { Notification::make() ->title('Invalid Serial Number') ->body("Serial number '$sNumber' should contain minimum 9 digits!") ->danger() ->duration(5000) ->send(); } else { $leakTestQrExists = LeakTestReading::where('plant_id', $plantId)->where('item_code', $iCode)->where('serial_number', $sNumber)->first(); if (! $leakTestQrExists) { Notification::make() ->title('Leak Test QR Not Found') ->danger() ->duration(5000) ->send(); } else { Notification::make() ->title('Leak Test QR Found') ->success() ->duration(5000) ->send(); } } } $this->leakTestQr = null; $this->form->fill([ 'plant_id' => $this->plantId, 'leak_test_qr' => null, ]); } public static function canAccess(): bool { return Auth::check() && Auth::user()->can('view leak test validation page'); } }