F
Filament6mo ago
Steff

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 Koch6mo 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
SteffOP6mo 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
LeandroFerreira6mo ago
are you using formatStateUsing?
Steff
SteffOP6mo ago
No. I got the error msg: Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization
LeandroFerreira
LeandroFerreira6mo ago
where?
Dennis Koch
Dennis Koch6mo ago
It’s triple backticks. See #✅┊rules
Steff
SteffOP6mo 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
SteffOP6mo 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 Koch6mo ago
You should use ->formatStateUsing not ->state
Steff
SteffOP6mo 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); }), ´´
Want results from more Discord servers?
Add your server