Action don't works on custom ViewRecord page
I'm having problem when using actions on a custom view of a viewRecord page. The action is printed but don't works.
Controller
View Blade Template
<?php
namespace Maat\VisualTesting\Resources\VisualTestingResource\Pages;
use Filament\Actions\Action;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\ViewRecord;
use Filament\Support\Enums\MaxWidth;
use Maat\VisualTesting\Resources\VisualTestingResource;
use Maat\VisualTesting\Services\VisualTests\VisualTestsServiceInterface;
class ProjectVisualTests extends ViewRecord
{
protected static string $resource = VisualTestingResource::class;
protected static string $view = 'visual-testing::filament.resources.visual-testing-resource.pages.project-visual-tests';
public function getRegenerateTokenAction(): Action
{
return Action::make('regenerate-token')
->color('success')
->icon('heroicon-o-arrow-path')
->hiddenLabel()
->tooltip('Regenerate token')
->action(function () {
$newToken = app(VisualTestsServiceInterface::class)->regenerateProjectToken($this->record->name);
if (empty($newToken)) {
Notification::make()
->title('Error regenerating token')
->danger()
->send();
}
$this->record->token = $newToken;
Notification::make()
->title('Token regenerated')
->success()
->send();
})
->requiresConfirmation();
}
}
<?php
namespace Maat\VisualTesting\Resources\VisualTestingResource\Pages;
use Filament\Actions\Action;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\ViewRecord;
use Filament\Support\Enums\MaxWidth;
use Maat\VisualTesting\Resources\VisualTestingResource;
use Maat\VisualTesting\Services\VisualTests\VisualTestsServiceInterface;
class ProjectVisualTests extends ViewRecord
{
protected static string $resource = VisualTestingResource::class;
protected static string $view = 'visual-testing::filament.resources.visual-testing-resource.pages.project-visual-tests';
public function getRegenerateTokenAction(): Action
{
return Action::make('regenerate-token')
->color('success')
->icon('heroicon-o-arrow-path')
->hiddenLabel()
->tooltip('Regenerate token')
->action(function () {
$newToken = app(VisualTestsServiceInterface::class)->regenerateProjectToken($this->record->name);
if (empty($newToken)) {
Notification::make()
->title('Error regenerating token')
->danger()
->send();
}
$this->record->token = $newToken;
Notification::make()
->title('Token regenerated')
->success()
->send();
})
->requiresConfirmation();
}
}
<x-filament::page>
<div class="mr-2">
{{$this->getRegenerateTokenAction()}}
</div>
</x-filament::page>
<x-filament::page>
<div class="mr-2">
{{$this->getRegenerateTokenAction()}}
</div>
</x-filament::page>
2 Replies
Solution
Please read the docs: Actions names must match the function name.
Oo, thanks. That works.