F
Filament•5mo ago
vahnmarty

How to access Model $record when using ->visible() or ->hidden()?

This is not working
TextColumn::make('email_verified')
->visible(fn(User $record) => $record->verified()),
TextColumn::make('email_verified')
->visible(fn(User $record) => $record->verified()),
i am getting this error:
App\Livewire\Portal\ManageUsers::App\Livewire\Portal\{closure}(): Argument #1 ($record) must be of type App\Models\User, null given, called in /Users/vahnmarty/Projects/mysi-v2/vendor/filament/support/src/Concerns/EvaluatesClosures.php on line 35
App\Livewire\Portal\ManageUsers::App\Livewire\Portal\{closure}(): Argument #1 ($record) must be of type App\Models\User, null given, called in /Users/vahnmarty/Projects/mysi-v2/vendor/filament/support/src/Concerns/EvaluatesClosures.php on line 35
10 Replies
Vp
Vp•5mo ago
try like this fn(?User $record)
vahnmarty
vahnmartyOP•5mo ago
I'm getting Call to a member function verified() on null hmmm, I think I'm implementing the wrong way. the hidden/visible function of TextColumn is to hide everything from that column.
Vp
Vp•5mo ago
What is the planning/requirement here.. it seems like you try to hide/show table column based on email_verified (which is bad UI) Why not just display true false based on whether it's null or not (good UI)
vahnmarty
vahnmartyOP•5mo ago
Yea you are right.
Vp
Vp•5mo ago
ok.. then just do TextColumn::make('email_verified_at')->placeholder('Nah') 🤣
Marcel
Marcel•5mo ago
Try using Get
->visible(fn (Get $get): bool => $get('is_company'))
->visible(fn (Get $get): bool => $get('is_company'))
Source: https://filamentphp.com/docs/3.x/forms/advanced#conditionally-hiding-a-field
Vp
Vp•5mo ago
Nah.. it's table.. not form, and showing/hiding column per something is a bad UI/UX
Dennis Koch
Dennis Koch•5mo ago
As VP mentioned this is not possible because it doesn’t make sense to show/hide Columns on a row level
PabloZagni
PabloZagni•4mo ago
I don't think it's a bad UI design. Sometime, we would like to show some fields according to the record type... in the same grid... like an activity log. Date, action, info related to that action...
PabloZagni
PabloZagni•4mo ago
I've found this... I'll try it
No description
Want results from more Discord servers?
Add your server