Is there an easy way to transform all labels to a different format instead of ucfirst (default) ?

I'm talking about everything that Filament has, from Panels to Forms to Tables. I've been using ->label() a lot because I prefer to have a Str::title() .
3 Replies
dwiser
dwiser8mo ago
Have you tried ->label(fn (): string => Str::title('my cool label'))
lukevi
lukevi8mo ago
I have done this in my AppServiceProvider (Laravel 10 - not sure where you'd do it in 11):
// Labels like 'Head Line' not 'Head line':
// instead of adding to each individual Filament/PanelProvider
$overrideDefaultLabel = function ($o): void {
$o->label(
str($o->getName())
->beforeLast('.')
->afterLast('.')
->headline()
);
};

Column::configureUsing($overrideDefaultLabel);
Field::configureUsing($overrideDefaultLabel);
Action::configureUsing($overrideDefaultLabel);
// Labels like 'Head Line' not 'Head line':
// instead of adding to each individual Filament/PanelProvider
$overrideDefaultLabel = function ($o): void {
$o->label(
str($o->getName())
->beforeLast('.')
->afterLast('.')
->headline()
);
};

Column::configureUsing($overrideDefaultLabel);
Field::configureUsing($overrideDefaultLabel);
Action::configureUsing($overrideDefaultLabel);
vahnmarty
vahnmartyOP7mo ago
that is what I have mentioned.
Want results from more Discord servers?
Add your server