F
Filamentβ€’12mo ago
ChesterS

`visible()` doesn't resolve record

I have the following Table
public function table(Table $table): Table
{
return $table
->query(...)
->columns([
IconColumn::make('visible_to_everyone')
->visible(fn (MyModel $record) => ! $record->created_by_admin) // Problem is here
])
;
}
public function table(Table $table): Table
{
return $table
->query(...)
->columns([
IconColumn::make('visible_to_everyone')
->visible(fn (MyModel $record) => ! $record->created_by_admin) // Problem is here
])
;
}
Which throws the following error
Argument #1 ($record) must be of type App\Models\MyModel, null given, called in /var/www/endor/vendor/filament/support/src/Concerns/EvaluatesClosures.php on line 35
Argument #1 ($record) must be of type App\Models\MyModel, null given, called in /var/www/endor/vendor/filament/support/src/Concerns/EvaluatesClosures.php on line 35
Am I missing something? It doesn't matter what type of column I use BTW, when I pass a closure to the visible method, it doesn't pass he record as expected. Everything is up-to-date (LW 3.3, Filament 3.1.23)
Solution:
In this case the check was on the user but I see what you mean. I can achieve the same result by either using the trueIcon()/falseIcon() class or by conditionally adding the column. I just thought using visible would be cleaner. Thank you both for your time πŸ™‡β€β™‚οΈ...
Jump to solution
3 Replies
DrByte
DrByteβ€’11mo ago
It appears that visible() isn't one of the methods that Filament sees as needing to inject the row's $record or the cell's $state. It does, however, let you run unrelated commands though: visible(auth()->user()->can('foo)), etc. However, this does appear to work:
->visible(fn(HasTable $livewire): bool => $livewire->activeTab === 'all')
->visible(fn(HasTable $livewire): bool => $livewire->activeTab === 'all')
... which is more about the Table, than about the Record.
Dennis Koch
Dennis Kochβ€’11mo ago
It doesn't make sense to hide single columns based on the record, that's why it's not injected. It would break the table structure if some rows had more columns than others.
Solution
ChesterS
ChesterSβ€’11mo ago
In this case the check was on the user but I see what you mean. I can achieve the same result by either using the trueIcon()/falseIcon() class or by conditionally adding the column. I just thought using visible would be cleaner. Thank you both for your time πŸ™‡β€β™‚οΈ
Want results from more Discord servers?
Add your server