F
Filament2mo ago
Akimbo

How do you call methods with a Custom Column?

I have been able to make a custom column, but I have been trying to figure out how to actually call methods. If I try to use it like a volt component, it is not able to to see volt functions Clicking here will give "toggleLiveStatus undefined"
<?php
use Livewire\Volt\Component;
use App\Models\Event;
$isDisabled = $isDisabled();
$state = $getState();
$id = $getRecord()->id;
new class extends Component {
public function toggleLiveStatus()
{
$record = Event::find($id);
$record->is_live = !$record->is_live;
$record->save();
}
};
?>

<div>
<x-filament::button
wire:click.prevent="toggleLiveStatus({{ $getRecord()->id }})"
:color="$getRecord()->is_live ? 'success' : 'gray'"
>
{{ $getRecord()->is_live ? 'Live' : 'Offline' }}
</x-filament::button>
</div>
<?php
use Livewire\Volt\Component;
use App\Models\Event;
$isDisabled = $isDisabled();
$state = $getState();
$id = $getRecord()->id;
new class extends Component {
public function toggleLiveStatus()
{
$record = Event::find($id);
$record->is_live = !$record->is_live;
$record->save();
}
};
?>

<div>
<x-filament::button
wire:click.prevent="toggleLiveStatus({{ $getRecord()->id }})"
:color="$getRecord()->is_live ? 'success' : 'gray'"
>
{{ $getRecord()->is_live ? 'Live' : 'Offline' }}
</x-filament::button>
</div>
Methods defined in the custom class itself will also don't register.
class EventLiveSwitcher extends Column
{
protected string $view = 'tables.columns.event-live-switcher';

public function toggleLiveStatus($eventId)
{
$event = Event::findOrFail($eventId);
$event->update([
'live' => !$event->live,
]);
$event->save();
}
}
class EventLiveSwitcher extends Column
{
protected string $view = 'tables.columns.event-live-switcher';

public function toggleLiveStatus($eventId)
{
$event = Event::findOrFail($eventId);
$event->update([
'live' => !$event->live,
]);
$event->save();
}
}
I really am just trying to make a callback for clicking on the columns button.
Solution:
Yes. But wire: will refer to the component which is the ListPage
Jump to solution
5 Replies
LeandroFerreira
LeandroFerreira2mo ago
Your ListPage is the Livewire component, so I think you should add the methods to this page
Dennis Koch
Dennis Koch2mo ago
Columns aren't Livewire components. That's why you can't call methods on them.
Akimbo
AkimboOP2mo ago
To clarify, columns aren't livewire components, but they can still use wire: attributes? Looks like most of the built-in filament columns do that.
Solution
Dennis Koch
Dennis Koch2mo ago
Yes. But wire: will refer to the component which is the ListPage
Akimbo
AkimboOP2mo ago
Got it, thank you.

Did you find this page helpful?