How to change a label for a field, in view page?

I have a Main Resource file, that defines the form like so (See attached image). I am needing to change the field label only when viewing a record, based on a if condition on what the value of this record is. For example: If value is FR then the label should be Company Registration France. How can I achieve so in the View Page file? <?php namespace App\Filament\Resources\AllClientsResource\Pages; use App\Filament\Resources\AllClientsResource; use Filament\Resources\Pages\ViewRecord; class ViewClient extends ViewRecord { protected static string $resource = AllClientsResource::class; protected function mutateFormDataBeforeFill(array $data): array { return $data; } }
No description
4 Replies
dissto
disstoβ€’4w ago
I guess you could do something like that:
Select::make('company_registration_country')
->live()
->label(function (Get $get, Select $component, $state){
// if you simply want the country code
return 'Company Registration ' . $get('company_registration_country');

// or you probably want the actual name of the country as opposed to the country code
return 'Company Registration ' . ($component->getOptions()[$state] ?? null);
})
->options([
'FR' => 'France',
'CZ' => 'Czech Republic',
]),
Select::make('company_registration_country')
->live()
->label(function (Get $get, Select $component, $state){
// if you simply want the country code
return 'Company Registration ' . $get('company_registration_country');

// or you probably want the actual name of the country as opposed to the country code
return 'Company Registration ' . ($component->getOptions()[$state] ?? null);
})
->options([
'FR' => 'France',
'CZ' => 'Czech Republic',
]),
πŸ€”
FilamentDEV
FilamentDEVβ€’4w ago
Thanks @dissto !
LeandroFerreira
LeandroFerreiraβ€’4w ago
Select::make('company_registration_country')
->live()
->label(fn (Select $component, ?string $state) => 'Company Registration '.(filled($state) ? $component->getOptionLabel() : ' Country'))
->options([
'FR' => 'France',
'CZ' => 'Czech Republic',
])
Select::make('company_registration_country')
->live()
->label(fn (Select $component, ?string $state) => 'Company Registration '.(filled($state) ? $component->getOptionLabel() : ' Country'))
->options([
'FR' => 'France',
'CZ' => 'Czech Republic',
])
FilamentDEV
FilamentDEVβ€’4w ago
Thank you 😊