F
Filament17mo ago
Scott

Dynamically setting a label on a relationship

Hi guys, I have a table column which shows related sites. It outputs really nicely when doing this:
Tables\Columns\TextColumn::make('sites.woocommerce_url')
->listWithLineBreaks()
->bulleted()
Tables\Columns\TextColumn::make('sites.woocommerce_url')
->listWithLineBreaks()
->bulleted()
However, I want to conditionally show a message if no sites have been connected yet. When trying to do this, I get the following error message: Attempt to read property "sites" on null
Tables\Columns\TextColumn::make('sites')
->label(function($record) {
if($record->sites->isEmpty()) {
return '<a href="/sites/create">Create Site</a>';
} else {
return $record->sites->pluck('woocommerce_url')->take(3)->join('<br/>');
}
})
Tables\Columns\TextColumn::make('sites')
->label(function($record) {
if($record->sites->isEmpty()) {
return '<a href="/sites/create">Create Site</a>';
} else {
return $record->sites->pluck('woocommerce_url')->take(3)->join('<br/>');
}
})
Any ideas what I'm doing wrong here?
Solution:
Nevermind, it works fine when I use html() instead of label()
Jump to solution
1 Reply
Solution
Scott
Scott17mo ago
Nevermind, it works fine when I use html() instead of label()
Want results from more Discord servers?
Add your server