Files
animethemes-server/app/Filament/TableActions/BaseTableAction.php
T
2024-06-27 06:22:16 -03:00

60 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Filament\TableActions;
use App\Concerns\Filament\Actions\HasActionLogs;
use App\Filament\RelationManagers\BaseRelationManager;
use Filament\Support\Enums\MaxWidth;
use Filament\Tables\Actions\Action;
/**
* Class BaseTableAction.
*
* Table actions are standalone actions.
* It is an action related to the table and not to an individual model.
* In filament, it is called the table's Header Actions.
* Don't confuse it with the header actions of an individual model.
*/
abstract class BaseTableAction extends Action
{
use HasActionLogs;
/**
* Initial setup for the action.
*
* @return void
*/
protected function setUp(): void
{
parent::setUp();
$this->requiresConfirmation();
$this->afterFormValidated(function ($livewire, BaseTableAction $action) {
if ($livewire instanceof BaseRelationManager) {
$this->createActionLog($action, $livewire->getOwnerRecord());
}
});
$this->after(function ($livewire, BaseTableAction $action) {
if ($livewire instanceof BaseRelationManager) {
$this->finishedLog();
}
});
$this->modalWidth(MaxWidth::FourExtraLarge);
$this->action(fn (array $data) => $this->handle($data));
}
/**
* Perform the action on the table.
*
* @param array $fields
* @return void
*/
abstract public function handle(array $fields): void;
}