The error you're encountering, "Using $this when not in object context," typically occurs when you try to use $this in a static context. In the code snippet you provided, the issue arises because the closure you are using for the action is not bound to an object context where $this is available.
In the Filament documentation, the example assumes that the closure is being executed in a context where $this is available, such as within a component or a class method. However, in your case, the closure is being executed in a static context, which is why $this is not available.
To resolve this issue, you can use the dispatch method in a way that doesn't rely on $this. Instead, you can use the dispatch helper function if you're within a Livewire component, or you can use an event system that doesn't rely on $this. Here's how you can modify your code:
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Table;
use Livewire\Component;
class YourComponent extends Component
{
public static function table(Table $table): Table
{
return $table
->columns([
IconColumn::make('playerAssignments')
->icon('heroicon-o-pencil-square')
->action(
Action::make('edit-player-assignments')
->action(function (Event $record): void {
// Use the Livewire `dispatch` helper function
dispatch('open-player-assignments-modal', ['event' => $record]);
})
),
// ...
]);
}
}
Make sure that your component extends Livewire\Component or is within a context where the dispatch helper function is available. This way, you can dispatch events without relying on $this.
If you're not using Livewire or if the dispatch helper is not available, you might need to implement a custom event system or use a different approach to handle the action.