Call $livewire->js in header actions?
I have this table action which just opens a link with a token, it uses the livewire component to execute javascript because you can't open a link with php.
Tables\Actions\EditAction::make(),
Action::make('login')
->button()
->color('info')
->label('Log in')
->action(function (Website $website, Component $livewire) {
//open wordpress link with token
$token = self::generateToken($website->id);
if (empty($token)) {
Notification::make()
->title('Error: Token Generation Failed')
->danger()
->send();
return '';
}
$url = 'https://www.' . $website->domain . '?token=' . urlencode($token);
$livewire->js("window.open('{$url}', '_blank');");
i'm trying to have this same action in my edit page header actions,
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
Actions\Action::make('login') etc etc.
]}
however getting various errors
App\Filament\Resources\WebsiteResource\Pages\EditWebsite::App\Filament\Resources\WebsiteResource\Pages{closure}(): Argument #2 ($livewire) must be of type App\Filament\Resources\WebsiteResource\Pages\Component, App\Filament\Resources\WebsiteResource\Pages\EditWebsite given, called in vendor/filament/support/src/Concerns/EvaluatesClosures.php on line 35
did i go about this the wrong way, how can i achieve this?
2 Replies
Solution
you can use
$this->js(...)
in the EditPagei love you