label('Trigger Extension Action') ->form([ Select::make('action') ->label('Action') ->options([ 'create' => 'Create server', 'suspend' => 'Suspend server', 'unsuspend' => 'Unsuspend server', 'terminate' => 'Terminate server', 'upgrade' => 'Upgrade server', ])->required(), Checkbox::make('sendNotification') ->label('Send Notification') ->default(false), ]) ->action(function (array $data, Service $record, Actions\Action $action): void { try { switch ($data['action']) { case 'create': $sdata = ExtensionHelper::createServer($record); if ($data['sendNotification']) { NotificationHelper::serverCreatedNotification($record->order->user, $record, $sdata); } break; case 'suspend': $sdata = ExtensionHelper::suspendServer($record); break; case 'unsuspend': $sdata = ExtensionHelper::unsuspendServer($record); break; case 'terminate': $sdata = ExtensionHelper::terminateServer($record); break; case 'upgrade': $sdata = ExtensionHelper::upgradeServer($record); break; } } catch (\Exception $e) { if (config('app.debug')) { throw $e; } Log::error($e); Notification::make('Error') ->title('Error occured while triggering the action:') ->body($e->getMessage()) ->danger() ->send(); $action->halt(); } Notification::make('Success') ->title('Action triggered successfully') ->body('The action has been triggered successfully') ->success() ->send(); }) ->color('primary') ->modalSubmitActionLabel('Trigger'), ]; } }