FilamentF
Filament10mo 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>


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();
    }
}


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
Was this page helpful?