Specific partly output of a text column.I know the ->limit(50) method.I need a

I know the ->limit(15) method. But i need another output. E.g. the original value is "A1234567" and I want to output "A67" Something like that: ``` $string = 'A1234567' $string2 = '**' strlen($string) $string3 = $string2($string, 0 , strlen($string) - 3) echo substr($string, 0, 1) . $string3 . substr($string, -2); output: 'A*67' ``` But how in filament. Probably something with formatStateUsing.
13 Replies
Dennis Koch
Dennis Koch5d ago
It's hard to tell what you want, since you didn't use code formatting and the formatting of your message was messed up
Steff
Steff4d ago
Yes, this is the right way. The example works for me in Tables\Columns but not in Forms\Components. Is that common? Do you have a help for that? How is the tag for code. Tab right, such as in mkdocs, doesnt work here.
LeandroFerreira
are you using formatStateUsing?
Steff
Steff4d ago
No. I got the error msg: Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization
LeandroFerreira
where?
Dennis Koch
Dennis Koch4d ago
It’s triple backticks. See #✅┊rules
Steff
Steff4d ago
If i put the exmple code in Forms/Components;
->state(function (Flexquery $record): float {
return $record->id * 3;
})
->state(function (Flexquery $record): float {
return $record->id * 3;
})
Steff
Steff3d ago
Not yet. I have to dive deeper in that. the type of coding is new to me. thanks. I got it. perhaps too complicated? ´´´´ Tables\Columns\TextColumn::make('token') ->state(function (Flexquery $record): string { $len = str()->length($record->token); return str()->mask($record->token . '', '*', -$len + 1, $len - 3); }), ´´´´ Th einput is A123456789 and the output is A**89. Thats what i want.
Dennis Koch
Dennis Koch3d ago
You should use ->formatStateUsing not ->state
Steff
Steff3d ago
Ok why. Because a string? Ok, so i dont need the . '' ´´´ Tables\Columns\TextColumn::make('token') ->formatStateUsing(function (Flexquery $record): string { $len = str()->length($record->token); return str()->mask($record->token, '*', -$len + 1, $len - 3); }), ´´