Htmlable label - illegal offset type

Hello, everyone.

I'm having a little problem with label(). My goal would be to replace the label text with a small image (a google logo).

The problem is that when I try to use a new HtmlString as the label value, it returns an error like ‘Illegal offset type’ no matter what I enter.

As soon as I enter a normal string instead, everything is fine.

I also found this example online:
->label(fn() => new HtmlString('I accept the <a class="underline" href="/terms" target="_blank">terms and conditions</a>'))


but I can't figure out what the problem is. Is it possible that it does work only on Forms?

Thank you all very much for your support 😄
Solution
@Dennis Koch I solved the problem:

in AppServiceProvider I created this function:
protected static function translateLabel(Field|Column $element): string
{
    $label = $element->getLabel();

    if($label instanceof HtmlString){
        return $label;
    }

    return __($label);
} 


and then:
Field::configureUsing(function (Field $field){
    self::translateLabel($field);
});

Column::configureUsing(function (Column $column) {
    self::translateLabel($column);
});


For now it's working 😄 thanks for your input!
Was this page helpful?